Just switch conditionally. The rewind_posts()
function allows you to loop through the same loop a second time, while the has_term()
function allows you to check if the currently looped post has a specific term of a specific taxonomy.
if ( have_posts() )
{
while ( have_posts() )
{
the_post();
if ( ! has_term( 'term_A_slug/term_A_id', 'taxonomy' ) )
continue;
// display post here
}
}
rewind_posts();
// Second loop
if ( have_posts() )
{
while ( have_posts() )
{
the_post();
if ( ! has_term( 'term_B_slug/term_B_id', 'taxonomy' ) )
continue;
// display post here
}
}
Related Posts:
- Display list of Sub-Categories and the posts they contain, within one main Category
- How would you create a “weekly” archive?
- How to have Multiple Archives Widgets, one archive widget per category (in a different page)?
- “Sticky” posts for each category (archive.php)
- Category archive is displaying all posts rather than the specific category
- Do not show sub categories in the loop on archive-product.php
- Problem with multiple loops in wordpress theme
- How to get category and archive title?
- get_categories for custom post type with a specific custom taxonomy attached
- How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling
- Should category.php and The Loop be used if the query needs to be customizable?
- Exclude the category from the WordPress loop
- What’s the URL for a category archive?
- get_field not displaying my custom field value
- Sort posts by tags in category pages
- Randomise results from a category page?
- Show div only if post is in specific category
- How to show a category post to a specific registered user
- Root level category, tag, author and archive pages to work
- Listing all posts from current category on page
- Display one latest post from multiple categories
- How do I get the total number of categories in a list of search results?
- Are Custom Taxonomy Templates Possible?
- I want exclude the particular category in sidebar
- Remove Archive Headline and Archive Intro Text fields on category and tag archive pages in WordPress Admin with Genesis framework
- Display only posts from referred category on date archive page
- Display products for a category, sorted by post_excerpt
- Using widget logic I want to show only a widget on the archive page if there are no posts
- Creating archive pages for children categories
- a-z list, categories and sub categories in loop
- WordPress categories being called “archives” in google links. How to remove?
- conditional for sub category on archive page
- weekly archive for custom category
- How to loop only categories without posts (+ show category featured image with acf) [closed]
- Additional featured post on first page
- Show all posts for a specific category/author
- How to remove category titles?
- create a page which displays a list of categories title+ short description?
- Query Posts Exclude Entire Category
- Category index featured image
- How can I define a custom archive for childs of a specific category?
- add_rewrite_endpoint returns 404 on archives
- Multiple category archive page
- Custom archive.php: retrieve right post categories?
- Customize category page for different custom taxonomies
- Inside a loop, how to change CSS class based on category name?
- Categories list loop – add separator every 3 categories [closed]
- WordPress alphabetical A-Z custom post type post result display
- Trying to get variables in hacked category dropdown
- How to Remove a Title from All Category and Tags Page?
- category__not_in and id values from variable
- why get_the_post_thumbnail( the_ID()) echos extra post id
- Allow user to select categories that will display in post loop
- Insert HTML content in WP Query at specific point
- display category list year wise in wordpress
- Two Sections on Woocommerce Catergory Page [closed]
- Getting the Most Recent Posts from Multiple Categories
- Display subcategories in dropdown
- Display category title and three latest post inside the category
- WordPress monthly archive category specific
- Show multiple categories in query using redux framework variable
- Archive filtering
- Show Secondary Sidebar on Category pages (archive)
- Rebuilding a Site: How to Show Several Category Posts in Woo Framework Theme?
- Limit Loop to One Category
- Add multiple orderby with pre get posts
- Filter Category Loop Dynamically
- the_category() doesn’t working in wp_query loop
- Conditional category query breaking?
- Category name for all posts getting assigned to a single random post
- Include last post date in get_categories loop
- How can I order all subcategories alphabetical independent of the parent categories?
- Custom Loop with certain number of one category
- how tho change number of posts in loop from specific categories
- Template category.php with page (no posts)
- I want to create a custom taxonomy page showing a list of subcategories
- error in specific category loop
- How to add excerpt and read more button to category archive page
- custom browse by
- Querying posts from two different categories while looping inside another loop
- Trying to display all posts in a category
- How to get get_categories()’s ‘hide_empty’ argument to work with global year var in the archive template?
- get_the_terms_list output last child only
- Loop doesn’t work
- How to get related category/categories in WordPress archive page
- Display Taxonomies in loop with template args
- How to loop through a custom field for each post, & display?
- show category name before first posts in each category
- How to count the number of monthly archive?
- Conditional statements based on custom meta value in category archives
- Displaying categories items among posts
- Category slug in in loop always the same?
- how to get number of posts in a category on a specific date
- How can I set up the URL for a category archive for a custom post type?
- Show posted on date only for posts in a certain category
- Custom loop by url
- Show all posts in category
- IF have_posts contains posts from a certain category
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Sorting past events by month