I’ve discovered a solution. I don’t know if it’s the best solution, but it does work.
GROUP BY wp_posts.ID
was causing my query to error out. I don’t quite understand why. In theory, my query should be returning duplicate posts without it… but it’s not. So, I’m going to push this code live as it is working as intended.
For concordance, this is the filter and corresponding function which I added to my construct function:
add_filter('posts_groupby', array($this, 'my_posts_groupby'));
function my_posts_groupby($groupby) {
global $wpdb;
$groupby = "";
return $groupby;
}
For more information, read Filter GROUP BY on WP ORG codex.
Related Posts:
- Nested meta_query with multiple relation keys
- Does tax_query really beats meta_query in all situations?
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- Tax query clause inside a meta query clause?
- Is it a good idea to improve meta query performance by adding tax query?
- Tax query AND/OR meta query [duplicate]
- Query with meta_query and tax_query together not working properly
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- Is it possible to add relation between meta_query and tax_query?
- WP_Query for a taxonomy value OR a custom post type meta field
- Custom query with custom filtering returning incorrect results
- How to query posts based on lat-lng coordinate as post meta?
- Set Alias for meta_query arguments in get_posts()
- Add indexing to meta_value in wp_postmeta
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- Is it possible to wrap Geo Location search around WP_Query?
- Custom WP_Query order by post_meta and (author) user_meta
- Using custom meta_query with relation not working as expected
- Perform query with meta_value date
- WP_Query meta_query where meta value ends in space
- Nested query inside Logical operator OR not working in meta_query
- What is an efficient way to query based on post_meta?
- How do I create my own nested meta_query using posts_where / posts_join?
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Compare two meta-fields in a wp_query (where meta-field-A is larger than meta-field-B)
- How to combine tax_query and date_query in WordPress
- Exclude post on loop by multiple meta key value
- Using tax_query reverses my post_type argument in a custom WP_Query
- get complex results set according to category structure
- Order posts by meta value and Date
- Query sticky posts with thumbnails
- WP_Query tax_query problem
- Order WP Query posts by custom order calculated from post meta values
- how to speed up a complex wp_query?
- Meta query with order by another custom field
- Empty tax_query array returns an empty array
- Creating arguments from loop for WP_Query meta_query
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- Single meta_query query using OR instead of AND in request’s WHERE statement
- How to do meta_query for attachments?
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Why isn’t my `meta_query` array functioning properly?
- Overwrite YoastSEO meta-tags with another page’s [closed]
- How to orderby multiple meta fields if some fields are empty
- Suggestions on making this query/code more performant
- Is it possible to set specific posts to show first in a query?
- Order by meta value (numeric value lower to higher)
- Large AND OR query timing out
- WP_Query with different postmeta filter for each categories
- Slow WP_Query with ‘OR’ on meta_query
- How to filter a query by multiple meta keys and order by other meta keys
- Meta Query doesn’t works as espected
- Advanced WP_Query with meta_query, orderby?
- Issues with search after added meta_query
- Display posts with specific value first in query
- WP_Query: apply an SQL function to meta fileld value
- How to create dynamic value in WP_Query meta_query
- query post by author gender
- How do I add an item to the WP admin menu?
- Multiple meta query from array
- WP_Query with 4 post meta field arguments gives 500 internal server error
- Tax_Query using WP_Query not working
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- Any quicker alternative for WP_Query “NOT IN”
- Custom meta_query order for Elementor based on post meta key [closed]
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- ElasticPress is (aparently) messing with my search filters
- Meta query ignores multiple values of the key
- Multiple meta_query not returning rows
- meta_query order by date present -> future then show null
- Check for not NULL not working in meta query
- Get unique post by meta value using wp_query
- Query against multiple locations within single custom post type post
- WP_Query, ACF field and array
- Order by Date Custom Field
- WP Query. Ordering posts by another post types meta
- Complex Meta Query
- Get posts meta_query by repater field
- Query 3 meta_key and orderby
- wp_query sorting – one specific meta_key value at last and then sort by create date
- How can I get all the posts that are related with a specific taxonomy term?
- How to combine nested tax_query logic with other nested query logic?
- tax_query not working for taxonomy slug
- Custom query for tag and custom tag from 2 post type
- Filter posts/pages by user_role array
- WP_Query with MetaQuery issue
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- WP_Query with meta_value_num and meta_query not paged correctly
- Post Query not working after updating to 4.1
- Orderby Meta Value and Query from Meta Query
- The sorting of posts by a meta_query with two keys fails while separated as single queries it works
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- Sort Posts with custom meta key by default which is currently set as optional
- WP_Query with several meta_query-statements and order by meta_value
- Output ACF field dynamicaly within a taxonomy loop [closed]
- How do I have multiple metaqueries inside one wordpress query
- WP query with multiple custom meta not respecting orderby
- Display only posts with thumbnails