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
- Get the children of the parent category
- How to check if I’m on the last page of posts?
- How to get category and archive title?
- Get rid of WordPress category, tag and author archives?
- Category archive by year with permalink support /category/YYYY
- 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?
- 404 Error On Category and Tags Pages
- Exclude the category from the WordPress loop
- Force WordPress to Show Pages Instead of Category
- How do I get the category URL from get_the_category?
- Decreasing the Memory Consumption of a WordPress Site?
- What’s the URL for a category archive?
- get_field not displaying my custom field value
- Default WP Gallery – show only galleries of a certain category
- Rearranging posts based on categories
- WP_Query not looking at child category
- Sort posts by tags in category pages
- Randomise results from a category page?
- Display all posts in category, with specific tag posts at top
- Show div only if post is in specific category
- How to get the category of the post and link it to the archive (of the category)
- How to hide a specific category posts in my monthly archive?
- Optimal way to redirect home page to category archive?
- Display posts links from a category group by year
- How to show a category post to a specific registered user
- Loop with Dynamic Categories
- How can I create a loop to build slides based on multiple categories using Coda Slider
- Sort category page with custom field
- How to create tabled index of posts in a certain category
- Remove child products from woocommerce category page [closed]
- Get a list of commas separated categories inside a loop
- Categories list loop – add separator every year
- Sticky Posts Not Sticking to Top of Category Archive
- How to exclude categories from recent posts, recent comments & category widgets?
- Root level category, tag, author and archive pages to work
- Listing all posts from current category on page
- Removed slug from CPT, now How/where do I hook the filter to the taxonomy term archive pages link?
- Display one latest post from multiple categories
- Category Specific Archive
- How do I get the total number of categories in a list of search results?
- Are Custom Taxonomy Templates Possible?
- Check if post belongs to any category
- I want exclude the particular category in sidebar
- How do I display the posts from a custom post type on a category.php page?
- How to group the loop posts in a particular by author?
- How to filter archives both by category and tag?
- 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
- What type of page should i use? static page or category page? and what’s the difference? [closed]
- Exclude category from loop not working
- Creating archive pages for children categories
- How to list custom post types?
- Listing Parent, Child and GrandChild Categories and then the PostTitles on Page Template !
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- Display “add to cart” button on every listing in product category page?
- If newest post of category is newest post in general, skip first post of category
- a-z list, categories and sub categories in loop
- WordPress categories being called “archives” in google links. How to remove?
- Why would in_category only return one post in a specific category?
- conditional for sub category on archive page
- Is it possible to select and edit the way the most recent post from a certain category is displayed on the page?
- Sorting posts by season
- weekly archive for custom category
- WP_Query() returns null when results exist!
- Displaying multiple loops based off of category
- CPT Archive with core Category
- How to loop only categories without posts (+ show category featured image with acf) [closed]
- WordPress subcategories return 404 in custom template
- Additional featured post on first page
- Show all posts for a specific category/author
- How to remove category titles?
- Show archives by year from just one category
- Redirect category to url with /category
- create a page which displays a list of categories title+ short description?
- Enter a variable in the ‘category_name’ parameter
- Archives for each category on WP Multisite
- Second level subcategory
- how to define category loop last class in the third
- Query Posts Exclude Entire Category
- Category index featured image
- Archive.php filtered by pre-determined category
- How do I call posts with a certain tag?
- Class active for Archive link – looped out
- Taxonomy name repeating when showing 2 posts from each category
- Category being displayed without base parmalink
- How to change category and year archive permalinks/rewrite rules?
- How can I define a custom archive for childs of a specific category?
- Display the last post by each category?
- Get parrent category name