Just loop over the posts and bump the count based on the value of ads_class
:
$ads_1 =
$ads_2 =
$ads_3 = 0;
while ( $ads->have_post() ) {
$ads->the_post();
switch ( ( int ) get_post()->ads_class ) {
case 1 :
$ads_1++;
break;
case 2 :
$ads_2++;
break;
case 3 :
$ads_3++;
break;
}
}
$ads_1; // Number of "1" ads
$ads_2; // Number of "2" ads
$ads_3; // Number of "3" ads
Related Posts:
- Count number of published posts by type
- For each 3 posts, show a different post type
- WP_Query | Help me create a search term with an ‘OR’ relation?
- Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?
- How to change post count in wordpress loop?
- WP_Query use for a filter with multiple Taxonomies and Terms
- Duplicates with WP_Query loop
- Count total number of post in foreach loop
- Display Post co-authored in Author Page
- Display related products with custom output
- How do I dynamically generate args for wp_query?
- Sorting Posts | Alphabetical Order
- Looking for most performant way to execute several similar WP queries within shortcodes
- Use wp_get_recent_posts with search term
- have_posts() execution failure
- 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?
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Custom page archive query by url var calling page twice on one of my custom queries?
- How to query for posts with a null or blank post_name?
- WordPress pagination not working with search page
- How to make sure content doesn’t display if selection is empty
- WP Query with custom Shortcode
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- User’s total comment count excluding comments on their own posts
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Add more button if more 8 items
- How to store post ID’s in cookie or session to display the same posts later
- Exclude posts based on meta value
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- auto-populating custom nav with all items from custom post type
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- WordPress theme options error
- Get posts from multiple post type
- WP_Query fails despite having 1 post
- wp_query get the 2nd post
- How to add div blocks after certain set of post
- How can i count the post added in relationship field, theme display
- the_posts_pagination() not working in wpquery
- WP_Query: getting posts where custom field exists
- Convert a string into a decimal number for use in query
- Increment paged on WP_Query
- Hide posts if user is added to it WP_query
- Custom route and query
- Getting posts to exclude from array
- How to hide posts of a specific custom category in WordPress?
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Custom post type permalinks do not appear using the link functions
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- Modify main query before it run without pre_get_post
- WordPress WP_Query without query GET parameters
- Sort posts in a specific way
- array_rand not working correctly?
- WP_Query() load selected post
- How to extract information from a wp_query result?
- posts_nav_link pulling in multiple post types
- displaying a fall back query if there’s nothing in the post-type category
- Modifying WP URL handing code?
- orderby meta_value_num is not working, giving default order
- How can I modify this code to make the search box include tags and meta
- Free search and custom taxonomy query not providing the same result
- How do I reset $wp_query in a function?
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- WP_Query for woocommerce products with a pattern as a post_title
- wp_query with multiple arguments with AND
- How do I make these combination select filters work when only one dropdown is set? They work in WordPress 5.8.2 but don’t in 5.8.3
- Replace a single variable with add_filter
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- Sending simple variable on single page to WP JSON
- How to exclude meta no index pages from wp_list_pages
- in_array not working on dev server but works on localhost
- meta_query search names when they have middle initials
- Ajax filter with loadmore button
- Define global custom post
- How can I show how much water got saved on this order (making use of the number of items bought) on a thank-you-page?
- Query by pagename not Working
- Display featured image of post type category
- Delete post meta by serialized meta value
- get_filtered_term_product_counts – Get product terms if any products
- Search for single post by 2 tags
- Getting info about selected posts using one WP_Query
- List all ACF field values across every post on one page
- Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields
- Query to show average # of months all accounts with specific role have been active
- Woocommerce Related Product by 2 taxonomy
- Query doesn’t display text data with apostrophes
- How to return count of items found in SQL query
- Querying posts from wordpress with 2 or more conditionals
- SQL Query Search page
- Can’t get data from audio media
- Display Year and Month from custom field + Age Calculator
- insert thumbnail image from php script
- Masonry layout within the loop
- Query seems to be duplicated
- 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 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