$countries
is not a number, but w WP_Query
instance, so you can’t compare it with a number…
This means that you should replace this:
if ($countries > 7) {
with:
if ( $countries->found_posts > 7 ) {
It will check if there are more than 8 countries that match your criteria. This way you can even change ‘-1’ to ‘8’ and limit the number of posts you’re displaying and this condition will still work.
Related Posts:
- How to exclude meta no index pages from wp_list_pages
- Using a new WP_Query inside the loop
- wp_Query with mutuplea values returns all posts
- Load more posts using AJAX based on posts inside WP_Query
- in_array not working on dev server but works on localhost
- wp_query – Exclude the first thumbnail from lazy loading on archives
- meta_query search names when they have middle initials
- How to call my PHP function with AJAX ? wp_query
- WordPress sorting posts by date and title using a dropdown
- Custom search query on WordPress page not working
- WP query posts BUT show the most recent and one per author
- How to get specific multiple pages excerpts at homepage?
- Ajax filter with loadmore button
- Define global custom post
- How to select post ID for given parent name with nested prepared queries?
- posts_per_page displays only 2 posts instead of 4 posts
- Usermeta data unserialize, extract and display in table in WordPress
- Use WPQuery to match to specific repeater row in post
- Query by pagename not Working
- Query on a repeater date (acf)
- WP_QUERY post_in problem
- Display featured image of post type category
- how to get data from two different table from wordpress database
- Delete post meta by serialized meta value
- can I extend the WP_Query class to deal with ‘duplicate’ posts created by joining to wp_posts?
- Assign meta_query value to php variable
- get_filtered_term_product_counts – Get product terms if any products
- Trying to get pagination working on WP_Query() post grid
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Add code to the header of posts by particular author
- Search for single post by 2 tags
- Paged WP_Query is quitting on page 3
- Getting info about selected posts using one WP_Query
- Get Child of Child Pages in custom Menu
- List all ACF field values across every post on one page
- WordPress search query, how to modify the sql
- Modify post image in full size
- Wp-query output correct, but the loop shows one less item (only sometimes)
- Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields
- How to display sticky post always at the top (before regular post) in wordpress?
- WP_Query To Display Product Of Brand On Taxonomy Page
- Meta query not showing result properly
- Combine multiple queries, array_unique returns nothing
- How to display last whole post on the homepage
- Query to show average # of months all accounts with specific role have been active
- wordpress query returning unexpected results
- Woocommerce Related Product by 2 taxonomy
- Custom Post type Ajax search results
- Help on Wp_query to print an term
- Making list of posts with chosen description
- Query doesn’t display text data with apostrophes
- Ordering / grouping posts by datepicker ACF
- How to return count of items found in SQL query
- Include search tags and users in my search results system
- Display only upcoming events / Show all events when archive year is selected
- Add custom taxonomy to custom search for posts
- making a search.php query
- wp_query beginner
- Querying posts from wordpress with 2 or more conditionals
- My query keeps looping infinitely ! how to stop it?
- Efficient way of querying for a “fallback” post?
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- SQL Query Search page
- How can I display a query in a page?
- How to add thumbnails from recent posts to owl-carousel in wordpress automatically?
- direct query to post_meta table
- For each 3 posts, show a different post type
- Add post class in custom loop (WP_QUERY)
- Only Get A Certain Number of Posts From WP_Query
- Can’t get data from audio media
- Create a hierarchical loop at predefined markup requirements
- Display Year and Month from custom field + Age Calculator
- insert thumbnail image from php script
- Count custom posts type and filter by tag
- Three different queries on same page
- How to sort custom sortable column by custom table value
- /page/2/ redirect to 404
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- AJAX WP_Query’s order and orderby parameters not working
- Add adjacent post function inside custom recent post function
- How to sort search result by post_title, then by post_content
- How do I exclude the current post from the upcoming post query
- How do I display WooCommerce products in my query to rows of 3?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- wp_logout action hook is not firing
- How to show correct td of table tags in wp_query loop
- Exclude first post from wp query
- Show post in elementor based on views and specific category with query id feature in elementor
- Check for a value in a custom query
- How to make posts_like_dislike reference current post when iterating?
- AND and OR in my CPT search query depending on checkbox
- Add css class ID to largest and smallest number a custom field in wp_query
- External WP_Query call from PHP crashed after version update
- How could I prevent using the same custom loop in a template file when I only need to change one meta_query parameter?
- Add up all numbers from a WordPress query [closed]
- Developing a “fallback” for empty wp_query results based on post dates
- Display posts in correct month order using single date custom field
- How can I save the HTML output of a WP_Query function as a variable?
- WordPress query_posts with multiple tax_query