Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 为什么从类别id获取文章不';行不通_Wordpress - Fatal编程技术网

Wordpress 为什么从类别id获取文章不';行不通

Wordpress 为什么从类别id获取文章不';行不通,wordpress,Wordpress,使用以下代码从category 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($p

使用以下代码从category 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类下有很多帖子


提前感谢。

这是自定义帖子类型“公文包”上的自定义分类类别吗?如果是这样的话,类别就不会得到它;你需要用一个。谢谢。我解决了。必须在get_帖子中使用“tax_query”。
/* 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();