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
- Meta_query compare operator explanation
- meta_query with meta values as serialize arrays
- meta_query ‘compare’ => ‘IN’ not working
- Multiple relationship for multiple tax_query in WP_Query
- Use REGEXP in WP_Query meta_query key
- WP Query Args – Title or Meta Value
- Meta query with string starting like pattern
- WordPress tax_query “and” operator not functioning as desired
- compare meta_query in get_posts arguments
- How to query posts based on lat-lng coordinate as post meta?
- how to show posts that are missing a meta_value
- Set Alias for meta_query arguments in get_posts()
- Sorting: custom query with orderby meta_value_num THEN by title
- Conditional arguments for WP_Query and tax_query depending on if $somevar has a value
- Display products from specific category in shop page
- How to Compare Two Meta Fields
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Escaping WP_Query tax_query when term has special character(s)
- WP_Query with checkbox meta_query
- ACF Relationship Field Search Filtering [closed]
- 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
- Query WooCommerce orders where meta data does not exist
- Tax_query terms ID’s using variable
- Getting attachments by meta value
- Query Multiple Post types each with own meta query
- Execute a large WP_Query with many “AND” Meta_Queries?
- Query all posts where meta value is empty
- WP_Query min and max values
- Why is my WP_Query not working when tax_query terms are an array?
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- WP_Query using meta_query with relation OR and orderby meta_value doesn’t work
- Using custom meta_query with relation not working as expected
- Perform query with meta_value date
- querying with custom meta field with meta_query
- Order by two meta keys
- multiple meta key but get server load is very high
- Meta Query with date and time on the same Day before given time
- A WP_Query that will look for posts after 2 weeks ago OR with a certain meta value
- How to grab metabox value in wp_query meta_query key
- WP_Query meta_query where meta value ends in space
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Nested query inside Logical operator OR not working in meta_query
- Is “orderby” in WP Meta Query conflicting with Meta Query?
- Query by meta_key and order by meta_value_num return orderby date
- What is an efficient way to query based on post_meta?
- search query within custom taxonomy term, post title and meta field
- WP_Query not working as expected for attachments and custom meta_query
- if wp_query taxonomy term have posts
- datetime picker, timestamps and meta queries
- How do I create my own nested meta_query using posts_where / posts_join?
- Post queries by latitude and longitude
- 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)
- Wp_query order by multiple custom fields?
- How to combine tax_query and date_query in WordPress
- How can I create a WP_Query that returns posts where one meta_value
- Meta Query querrying several post types based on ACF fields is broken after update to WP 4.1
- WordPress altering my custom query, How to fix it?
- WP Meta Query for some meta (array) values
- Exclude post on loop by multiple meta key value
- Combine tax_query and meta_query in WP_Query
- Sort users by meta_value_num
- meta_query with array as value
- How to extend tag and category “Related Posts” query to custom post_type if the first 2 terms have no posts
- Using tax_query reverses my post_type argument in a custom WP_Query
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- How to get sum of meta_values of a meta_key in wp_query according to conditions
- How to query ‘posts_per_page’ to display a different blog posts index template?
- Find all product that contain terms with %keywords% in WP_Query
- Order by meta_key in custom post type doesn’t affect the query
- Get term by custom term meta and taxonomy
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- How to create/modfiy WP_Query to search in post title OR custom field?
- Using WP Query to search within ALL keys in meta query
- Order By Multiple Meta Fields
- WP Query – Get WooCommerce Products with variation that is in stock
- Meta_query with or without value
- tax_query shows no results if nothing is selected
- meta_key and meta_value not working together
- WP_Tax_Query with post_tag not working
- get complex results set according to category structure
- Use meta_query to display events by date in custom field
- Advanced WP Query hogs the SQL server
- Order posts by meta value and Date