Calling WP_Query
three times isn’t too good for performance, as it will make three queries to the database. The way you’re currently approaching this seems like the proper (and fastest) way in may opinion. However, you should be calling $category_posts->rewind_posts()
after each while-loop to reset WP_Query
‘s loop to the first post.
Furthermore, your current way of checking for a category (like “France”) isn’t very pretty. WordPress has a function to check whether a post has a term, has_term
, which is perfectly suited for your cause: has_term( 'France', 'category' )
(you can omit the last parameter, $post
, as it uses the current post in the loop by default).
Related Posts:
- Get the children of the parent category
- Check if a post is in any child category of a parent category
- Get all categories and posts in those categories
- How to make child categories recognize parent’s template displays
- Combine two taxonomies in a hierarchical tree
- How to get posts from two categories with WP_Query?
- Group WP_Query by category
- Exclude categories from search query
- How can I reduce the number of database query calls for this custom homepage?
- WP_Query not looking at child category
- Get page content by category or tag
- Excluding posts from a category but only if they’re not in multiple categories
- What could be causing my wp_query pagination to break?
- Custom query with category exclusion and post-meta “whitelist”
- Exclude most recent posts from specific category in wp_query()
- Show children of top level category only
- How can I make wp_list_categories output li with category-slug as class, for its children?
- Display one latest post from multiple categories
- How to Check if a Child Category is Being Queried
- How to run WP_Query to retrieve attachments to posts only from a particular category?
- How to query posts from specific authors and categories using WP_query?
- How to show in search results posts with a particular tag in a particular category?
- Custom WP_Query for current category (in category.php)?
- Show only first children level of current category?
- List Posts by Category for a Non-Zero, Non-NULL Custom Field Value?
- getting content from main domain to sub-domain using category and WP_Query
- WP_Query() returns null when results exist!
- Ignoring a category in WP_Query still shows the links in next_post_link()?
- 3 Columns, 3 Categories, One Archive, and Pagination
- Enter a variable in the ‘category_name’ parameter
- How to query post like normal search would do. within search.php page
- Query Posts Exclude Entire Category
- Category shows only top level child categories
- Multiple Loops on category.php with pagination on last loop
- How to get latest posts from each category in regular order
- change recent posts based on category
- How to remove specific categories from posts?
- Set colors depending on category
- Display posts from a category
- Custom loop of a single category, cannot order by date. What am I missing?
- Pagination on category.php and tag.php not working
- category__not_in and id values from variable
- Give Children Unique ID’s
- Use premade array as categories in wp_query?
- WP_Query – using category__and when one of the categories is 0
- More efficient way to list posts by category [duplicate]
- Adding a block with query in homepage
- Query posts by views on category page
- I need to exclude from a query a category and a few custom taxonomies
- Show multiple categories in query using redux framework variable
- Are term_taxonomy_id and term_id the same? [duplicate]
- Return category posts with WP_Query
- Using in ‘category_name’ in ‘$query->set();’?
- multiple values in an array for category__and does not work with WP_Query
- Custom Page Template Category loop not functioning correctly
- Retrieve post tags from from main wp_query
- Posts of specific category on page and excluded from index.htm
- new WP_Query issues
- Check is category parent with ids from the childs – get_term_children
- How can I use AJAX with check-box categories?
- Select posts that match multiple category names, must match all categories listed
- the_category() doesn’t working in wp_query loop
- How to display the 5 latest post titles but allow only 1 in there of a specific category
- Check for parent category
- How to create template for children category?
- Need list of child category post titles sorted by child category
- Unable to get all tags from specific categories
- category__and works, but why?
- foreach,having wp_query inside, breaks after showing one result
- Display related posts with same category or same tag return blank
- $args Orderby The number
- Querying Multiple Categories With Different Offsets
- WordPress Numeric Pagination with Query String [duplicate]
- Children categories not shown in dashboard
- Printing direct descendants of a category with WP_Query
- Custom Category Page Not Working [duplicate]
- list first post of Child Category on Category page
- WP_query exclude a category unless it has more than one catagory
- Show only one category in main query, issues on tag page
- Multiple Categories under one URL, where ‘Front Page’ is used already
- How do i add custom post types to this query?
- how to display page title only for child category pages
- Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce
- Trying to WP_Query a category
- WordPress check if user is logged in from non wordpress page
- How to group the loop posts in a particular by author?
- WordPress Genesis not excluding category from blog
- Categories for each brands
- Permalinks: display just one kind of wp category in the posts url
- get_post_meta not working on category.php
- Redirect Changed Permalink on wordpress
- Hide products in uncategorized category from search results
- Grandchild Term Things Grandfather Term is It’s Parent
- Search form options group categories
- How to exit out of delete_categories and stop action?
- How to test if the post is in a primary category
- Using wp_list_pages to create 2 lists of pages and include and exclude some of them depending on their category
- How to create default categories in new installs?
- How do I add and display a custom image field to a category? [duplicate]
- Add category image before post title on homepage