如何显示自定义postype类别的所有帖子?

我正在尝试显示来自单个自定义帖子类型类别的帖子。例如:我有自定义帖子类型:”课程”, 此帖子类型有三个类别:课程一, 课程二, 课程三。我需要单独显示该类别的所有帖子。

这是我的代码:

<?php
  $args = array (
  'post_type' => 'cource', 'cat' => 5, // id one of category
);

 $cat_one = new WP_Query( $args );
?>

<?php while ( $cat_one->have_posts() ) :  $cat_one->the_post(); ?>      
 <div class="widget_item">
    <figure style="background-image: url(<?=$url;?>)"></figure>
    <div class="widget_meta">
        <ul>
            <li class="widget_item_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
            <li><time><?php the_field('evente_date'); ?></time> 
            <li class="place"><?php the_field('evente_place'); ?> <i class="fa fa-map-marker"></i></li>
        </ul>
    </div>
</div>
<?php endwhile;?>

没有任何反应。如果我删除’cat’=> 5, 则所有帖子均以自定义帖子类型显示。请帮我解决这个问题。


#1


在查询中使用分类法参数:

$args = array (
  'post_type' => 'cource', 'tax_query' => array(
        array(
            'taxonomy' => 'cource', 'field'    => 'slug', 'terms'    => 'yout-taxonomy-term-slug-here', ), ), );

文件:https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

来源:

https://www.srcmini02.com/63251.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37661.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?