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 badges1 Answer
Reset to default 0Right 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
评论列表(0条)