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

I have created a new CPT called 'Properties' and have added a new taxonomy called 'Project Categories

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745260872a4619207.html

相关推荐

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

    I have created a new CPT called 'Properties' and have added a new taxonomy called 'Project Categories

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信