Php Wordpress查询类别

Php Wordpress查询类别,php,wordpress,post,categories,Php,Wordpress,Post,Categories,我面临一个奇怪的问题。我只想显示类别7的帖子。但对于以下代码,它没有显示任何内容: $featured = new WP_Query(array('post_type' => 'tours', 'posts_per_page' => 3, 'order' => 'DESC', 'orderby' => 'id', 'cat' => 7)); if($featured->have_posts()) {

我面临一个奇怪的问题。我只想显示类别7的帖子。但对于以下代码,它没有显示任何内容:

$featured = new WP_Query(array('post_type' => 'tours', 'posts_per_page' => 3, 'order' => 'DESC', 'orderby' => 'id', 'cat' => 7));
                if($featured->have_posts()) {
                    while($featured->have_posts()) : $featured->the_post();
                        echo the_title();
                    endwhile;
                }
我也在使用这个:

$featured = new WP_Query(array('post_type' => 'tours', 'posts_per_page' => 3, 'order' => 'DESC', 'orderby' => 'id', 'category__in' => 7));

但是什么也没发生。

在调用
$featured=new WP\u查询(数组('post\u type'=>'tours','posts\u per\u page'=>3,'order'=>'DESC','orderby'=>'id','cat'=>7))

请致电
echo$featured->found_posts
,查看您的查询中是否有帖子

请尝试此操作

 $args=array(
                      'category__in' => array('7'),
                      'post_type' => 'tours',
                      'post_status' => 'publish',
                      'posts_per_page' => -1,
                      'caller_get_posts'=> 1
                    );
 $featured = new WP_Query($args);
 if($featured->have_posts()) {
                while($featured->have_posts()) : $featured->the_post();
                    echo the_title();
                endwhile;
            }
试试这个

    $featured = new WP_Query(array( 'post_type' => 'tours', 'cat' => 7, 'order' => 'DESC', 'orderby' => 'id', 'posts_per_page' => 10 ));
    if($featured->have_posts()) {
      while ($featured->have_posts()) : $featured->the_post();
        the_title();
      endwhile;
    }

嗨Nadeem试试这个我希望你能找到你的答案

   $featured = new WP_Query(
    array(
        'post_type' => 'tours',
        'posts_per_page' => 1,
        'order' => 'DESC',
        'orderby' => 'id',
        'tax_query' => array(
                   array(
                    'taxonomy' => 'tours_cat',
                    'field' => 'id',
                    'terms' => array(7),
                    ),
                ),
            )
        );

除了第一段代码中的if语句外,从第一段到第二段的$characterized有什么区别?删除post_类型并检查一次,因为它在这里工作正常。如果它工作正常,问题不在于catbut@bhumisah post type比我创建它的taxaonomy重要,我想从这里调用dataYes,我理解,我只想确认问题在于post_类型,因此如果是,我可以在_title()中的solutionRemove echo中沿着该方向执行;这意味着,您的查询中存在问题。我该怎么办?我将只在WP_Query对象中输入
cat=>7
参数,最终输入另一个类别,然后检查
WP_Query::found_posts
中的帖子数量;然后随后添加其他参数和watch,哪个参数使查询返回zeroThanax Deemi这对我很有帮助