2013-11-21 165 views
0

我完全沉迷於此。下面的代碼允許我查詢多個帖子類型。由於使用了類別,我將它們分解成這樣。奇怪的是,我只從post_type ='post'獲取帖子。最後一個查詢我使用post_in來建立我想要的ID的帖子。如果我打印$ post_ids,我會得到我正在查找的確切ID。但我的最終查詢不會給我這些ID。思考?多種帖子類型的Wordpress查詢

$postArgs = array(
    'post_type' => 'post', 
    'cat' => '16,17,18', 
    'posts_per_page' => 5, 
    'orderby' => 'date', 
    'order' => 'DESC', 
    'post_status' => 'publish' 
); 

$videoArgs = array(
    'post_type' => 'occ-videos', 
    'posts_per_page' => 5, 
    'orderby' => 'date', 
    'order' => 'DESC', 
    'post_status' => 'publish' 
); 

$photoArgs = array(
    'post_type' => 'occ-photography', 
    'posts_per_page' => 5, 
    'orderby' => 'date', 
    'order' => 'DESC', 
    'post_status' => 'publish' 
); 



$docArgs = array(
    'post_type' => 'wpfb_filepage', 
    'posts_per_page' => 5, 
    'orderby' => 'date', 
    'order' => 'DESC', 
    'post_status' => 'publish' 
); 


$posts_query = get_posts($postArgs); 
$docs_query = get_posts($docArgs); 
$video_query = get_posts($videoArgs); 
$photo_query = get_posts($photoArgs); 


// start putting the contents in the new object 
$all_posts = array_merge($posts_query, $docs_query, $video_query, $photo_query); 

$post_ids = wp_list_pluck($all_posts, 'ID');//Just get IDs from post objects 

print_r($post_ids); 


$artArgs = array(
    'posts_per_page' => 20, 
    'post_status' => 'publish', 
    'orderby' => 'post__in', 
    'post__in' => $post_ids); 


$artQuery = get_posts($artArgs); 

回答

1

我的理解是,Wordpress總是默認爲post_type post。所以只能找到具有這些ID之一的帖子 - 並忽略您的自定義帖子類型。

試圖添加一行到您的$artArgs

$artArgs = array(
    'post_type' => array('post','page','occ-videos','occ-photography'), //Add this line 
    'posts_per_page' => 20, 
    'post_status' => 'publish', 
    'orderby' => 'post__in', 
    'post__in' => $post_ids 
); 

並添加任何文章類型你需要的WordPress查詢。

相關問題