最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Display Custom Post Type Based on Taxonomy With WP_Query()

programmeradmin4浏览0评论

I would like to pull in 3 posts from a custom post type called 'articles' that have a 'Featured' custom taxonomy term.

I'm using the code below, but it isn't pulling in just the posts with the 'Featured' taxonomy term, and I can't seem to get it work.

The 'Featured' taxonomy term is an additional taxonomy term used with other taxonomies terms for this post type (i.e a post could have the taxonomy terms 'Featured' and 'SEO').

Any suggestions would be really welcome.

<?php 
    $homePageFeatured = new WP_Query(array(
        'posts_per_page' => 3,
        'post_type'=> 'articles',
        'tax_query' => array(
            array(
                'taxonomy' => 'articles_categories',
                'terms'    => 'Featured',
            ),
        )
    ));

    while(  $homePageFeatured->have_posts()){
            $homePageFeatured->the_post(); ?>

            <article>
                <!-- HTML FOR TAXONOMY  -->
            </article>

<?php } ?>
<?php  wp_reset_postdata(); ?>
发布评论

评论列表(0)

  1. 暂无评论