$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:
- Best Practice for PHP
- retrieve thumbnail from post ID of best selling product in category
- How to create a WP_Query to search the Title or Tag?
- how to display active, upcoming and past event with featured listing with pagination
- Get list of WP Updates Across Sites
- if statement on database query
- Duplicates with WP_Query loop
- WP_Query meta_query results date by date
- WP_Query sort using multiple numeric meta values
- Help with adding pagination to custom wp_query
- How to get to a specific position in wp_query?
- API response to be stored locally
- WP_Query loop, does not display special characters in title correctly
- Remove query string specific key value
- have_posts() execution failure
- How to filter posts by post format “standard” from wp-json api?
- Can’t search posts using WP_QUERY inside AJAX Function
- How can I use wp_query to show all product data using just the products ID?
- Using foreach loop breaks
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- How to store post ID’s in cookie or session to display the same posts later
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- auto-populating custom nav with all items from custom post type
- Fatal error: Call to a member function query() on a non-object
- Is it possible to retrieve all posts with a certain value for metadata?
- unable to use ‘new WP_Query’ in AJAX call
- How to get post ID in a Page?
- Trouble inputting variable into WP query
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- How to display SQL query that ran in WC_Order_Query?
- Array to string conversion on array_map
- Store metakey value as an array
- Target post_date_gmt if it’s empty or not set
- Get all posts as an array ID => Name
- How to hide posts of a specific custom category in WordPress?
- Post not populating for custom post type based on category selection
- Passing an array into WP_Query as a variable
- Custom query vars filters problem with pagination
- WordPress meta_query >= &
- WordPress WP_Query without query GET parameters
- Do not duplicate posts with multiple categories in multiple loops
- Infinite Loop – WP_Query
- Dividing the loop to style post differently
- Displaying Event within two given time frames
- Remove Post if Advanced Custom Field is checked to fix paging
- displaying a fall back query if there’s nothing in the post-type category
- WordPress SQL JOIN query
- WP_Query and help with the loop for magazine front page
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- WP_Query: How to get results from both meta_key options?
- How to WP_Query posts order by parent title?
- Output product category link from WP_Query
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- wp_query with multiple arguments with AND
- Passing in MySQL prepare statement parameter separately throwing error
- Nested Queries of decreasing specificity
- Wrong pagination results, page counter resets when navigating
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- 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
- Custom search query on WordPress page not working
- WP query posts BUT show the most recent and one per author
- 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
- Use WPQuery to match to specific repeater row in post
- Assign meta_query value to php variable
- Need to show 7 posts from actual date
- 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
- Get Child of Child Pages in custom Menu
- Meta query not showing result properly
- Woocommerce Related Product by 2 taxonomy
- Help on Wp_query to print an term
- Making list of posts with chosen description
- Ordering / grouping posts by datepicker ACF
- Include search tags and users in my search results system
- making a search.php query
- Efficient way of querying for a “fallback” post?
- How to add thumbnails from recent posts to owl-carousel in wordpress automatically?
- 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
- WP_Query count of different meta key values [duplicate]
- Querying posts based off a jquery datepicker
- Use custom get results query to show posts WordPress
- Query seems to be duplicated
- Keeping the previous get value and add another value when submitted
- Pagination in category.php not functioning
- Fix incorrect related posts code snippet
- wp_query on search results page showing all results every time
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- How do I exclude the current post from the upcoming post query
- wp_logout action hook is not firing
- Add up all numbers from a WordPress query [closed]
- Developing a “fallback” for empty wp_query results based on post dates