The post_type isn’t really a meta query – therefore, both of these post_types would at least 1 category added/queried in order to get the filter invoked – using plain SQL is still a last resort.
add_filter( 'posts_groupby', 'my_posts_groupby' );
function my_posts_groupby($groupby) {
global $wpdb;
$groupby = "{$wpdb->posts}.post_date";
return $groupby;
}
According to your example (I’d guess one can pass it like that as well):
$args = array(
'posts_per_page' => 10,
'orderby' => 'date',
'groupby' => 'date', /* unsure about the parameter, should be easy to find out */
'post_type' => array('type1', 'type2')
);
Related Posts:
- Meta Query for specific months
- date_query seems to be ignored by wp_query
- Query custom post type by date field only working when two posts match the query
- Query Posts by date range with fixed beginning and end
- Get posts that were most recently tagged
- When should you use WP_Query vs query_posts() vs get_posts()?
- order by numeric value for meta value
- How to query for most viewed posts and show top 5
- WP_Comment_Query pagination, delving into the unknown
- Sort posts by category name and title
- What is the most efficient way of querying posts based on visits and date for current day?
- Custom WP_Query order by post_meta and (author) user_meta
- WP_Query for WooCommerce Products
- WordPress Custom Query to show posts from last x years
- Perform query with meta_value date
- Highlighting Sub topic in a post?
- how to retrieve specific product attribute value in an sql query?
- WordPress custom archive page
- WP_query category__in not working, only pulls from first category
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Retrieve or Query Pages by ID
- How do you query wordpress posts using a math formula between multiple meta field values?
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- How to do a query on custom taxonomies that is uncategorised?
- Empty tax_query array returns an empty array
- How do I search inside specific taxonomies in WordPress
- Different string for specifed post type on posts listing at homepage
- if/else on custom query gives 200 OK when condition not met?
- How to correctly pass values to wpdb->prepare()?
- Complex date range with WP_Query and BETWEEN
- Setting get_queried_object
- remove query arg from url after set query
- difference between like ‘%%%var%%’ and ‘%var%’
- Query all published post AND attachment with specific mime type
- only delete post within query / for each statement (front end)
- Complex WP_Query order request: DESC by day, but then ASC by time
- How to detect if query is runned from widget?
- Sort query by author: 1 author, then others
- Overwrite YoastSEO meta-tags with another page’s [closed]
- How to orderby multiple meta fields if some fields are empty
- How to duplicate 5 posts out of WP_Query results?
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- How to display user order by role
- WP_query sorting can’t sort danish letters (æ, ø, å)
- Slow queries on a huge database
- Multisite pagination issue by multi query archive 404
- Query with relation and one without relation using multiple taxonomies?
- How to get list of posts from permalinks?
- Is there a reason why Pages are not publicly_queryable?
- Check return value of get_posts
- Exclude some authors from query
- Transient api Caches confused
- How can I override one post and make it display content for another post?
- Get multiple users with meta value in one query and populate WP_User class
- Get a list of posts by specific category
- How to check the array values, what WP_Query has brought to me?
- How to add custom meta to ‘pre_get_terms’?
- Shortcode for custom query not returning results when attributes are added
- Should I reset $wp_query?
- Get specific ACF key and value from all posts – no access to DB
- Limit loop to future events
- I am officially missing something about transient posts
- Insert images into wordpress post with a query
- Start Query from 2nd Post without offset
- Display upcoming events in the next 30 days by querying posts with timestamp in custom meta
- Post incorrectly excluded when using “category__in”?
- Display posts ONLY from the current logged in user and current week/year/month Elementor posts
- Any way to use FETCH_KEY_PAIR with $wpdb?
- pre_user_query vs pre_get_posts
- Query against multiple locations within single custom post type post
- Problem with my loops
- Sort posts on custom field AND after that sort on date?
- How to query users by post count no less than 10
- WP Query. Ordering posts by another post types meta
- How to make a search query if not found in post table then search in postmeta table?
- WP_Query about meta_key and its array value
- Create global array to compare inside a query
- Get posts by birthday
- how to show more than 1 post into three columns query
- Using the same WP_Query for shop and widgets in WooCommerce shop
- How can I get all the posts that are related with a specific taxonomy term?
- Filter posts/pages by user_role array
- Pagination in custom query in a category page
- Get a list of the last posts grouped by author and filtered by category
- When should you use WP_Query vs query_posts() vs get_posts()?
- Retrieve posts in custom post type and specific taxonomies
- Complex WP_Query Using Post Date And Post Meta
- Custom post types loop on a page template
- Get the number of rows from $wpdb->get_results not working
- Parsing External Table Arguments
- Get Child Custom Post Content on Single.php?
- difference between methods of query
- Create a list of months based posts
- Query posts by meta value and sort by another meta key
- How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page
- how to use transient method?
- Pre_get_post on CPT archive page
- A Depth Like Parameter For “get_posts”
- Search query alteration not working for meta values
- Advanced Search – Is this possible?