2013-11-21 126 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查询。

相关问题