仅在Wordpress自定义帖子类型页面上显示单个类别

时间:2016-01-04 17:17:14

标签: php wordpress wordpress-theming

我已经为我网站上的页面制作了自定义字段等自定义字段等...目前它工作正常并显示我创建的所有课程:http://seedcreativehub.co.uk/book-seedcreativehub-courses/

但是,我现在只想让页面显示一个特定的课程类别。

我正在使用的代码如下,我认为这就像添加'category_name'=>一样简单帖子类型下面的“即将发生的事件”,但它似乎根本没有显示任何内容......

我无法想象我做错了什么,如果有人可以提供帮助,我们将不胜感激。

        <?php
          $args = array(
            'post_type' => 'courses',
            'category_name' => 'upcoming-event'
          );
          $the_query = new WP_Query( $args );
        ?>

        <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

          <div class="col-xs-3 course">

            <?php
              $thumbnail_id = get_post_thumbnail_id();
              $thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail-size', true );
            ?>

            <p><a href="<?php the_permalink(); ?>"><img src="<?php echo $thumbnail_url[0]; ?>" alt="<?php the_title(); ?>" graphic></a></p>
            <h3><?php the_field('event_date'); ?></h3>
            <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>


          </div>


          <?php $portfolio_count = $the_query->current_post + 1; ?>
          <?php if ( $portfolio_count % 4 == 0): ?>

          </div><div class="row">

          <?php endif; ?>


          <?php endwhile; endif; ?>

感谢您的关注,

肖恩。

1 个答案:

答案 0 :(得分:0)

在根据分类法查询帖子时,您必须使用tax_query参数。

{{1}}