2

使用以下代码从类别 id 获取投资组合类型的帖子,但它不起作用。

$args = array( 'numberposts' => $items, 'post_type'=>'portfolio','orderby' => 'post_date','order'=>'DESC','category' => 5 );
$posts = get_posts($args);
foreach($posts as $post){
    setup_postdata($post);
    $return_html='......';
}

但是,如果我将类别 ID 留空,则可以,并且会显示所有类别的帖子。我敢肯定,第 5 类下有很多帖子。

提前致谢。

4

1 回答 1

0
/* below mention code u may have the idea */ 
/* You have to not pass the category id in the argument. */
/* You have to pass category type and category slug*/
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10,'orderby' => 'post_date','order'=>'DESC','category-type' => $category-slug );
$loop = new WP_Query( $args );              
if($loop->have_posts()) :
while ( $loop->have_posts() ) : $loop->the_post();
/*... Your post data here */

endwhile;
endif;
wp_reset_query();
于 2012-12-24T10:32:43.217 回答