使用以下代码从类别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类下有很多帖子。
提前致谢。
答案 0 :(得分: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();