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

categories - Show Custom Post Type based on Category on Archive Page

programmeradmin1浏览0评论

I have created a new CPT called 'Properties' and have added a new taxonomy called 'Project Categories' which then have subcats called 'Current_projects' and 'Past_projects'. I want to have a button on the archive-property.php page which when clicked shows either one or the other category's related posts.

I used CPT UI to build both the taxonomy and the custom post.

in the archive-property.php, I have the following code:

<?php if( have_posts() ) : ?>
                <div id="post-list" class="columns property-grid">
                    <?php while( have_posts() ) : the_post(); ?>
                        <?php get_template_part( 'partials/content' , 'property' ); ?>
                    <?php endwhile; // while has_post(); ?>

                    <?php the_posts_pagination(); ?>
                </div>
            <?php endif; // if has_post() ?>

Inside the template partial it just calls the article information (title, excerpt, etc).

This pulls all my postings however in that Custom Post type. How do I have it so that it only pulls posts with 'current_projects'? I plan to have a div/tab system that filters between the two.

I have created a new CPT called 'Properties' and have added a new taxonomy called 'Project Categories' which then have subcats called 'Current_projects' and 'Past_projects'. I want to have a button on the archive-property.php page which when clicked shows either one or the other category's related posts.

I used CPT UI to build both the taxonomy and the custom post.

in the archive-property.php, I have the following code:

<?php if( have_posts() ) : ?>
                <div id="post-list" class="columns property-grid">
                    <?php while( have_posts() ) : the_post(); ?>
                        <?php get_template_part( 'partials/content' , 'property' ); ?>
                    <?php endwhile; // while has_post(); ?>

                    <?php the_posts_pagination(); ?>
                </div>
            <?php endif; // if has_post() ?>

Inside the template partial it just calls the article information (title, excerpt, etc).

This pulls all my postings however in that Custom Post type. How do I have it so that it only pulls posts with 'current_projects'? I plan to have a div/tab system that filters between the two.

Share Improve this question asked Aug 8, 2019 at 3:23 Xero1Xero1 1491 gold badge1 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Right now you are looping the default WP_Query. Better to define the exact query to fetch the exact posts you want. Here is a link to the complete guide of how to use it, and how to use taxonomies: https://developer.wordpress/reference/classes/wp_query/#taxonomy-parameters

发布评论

评论列表(0)

  1. 暂无评论