Opened 10 months ago
Last modified 10 months ago
#21683 new enhancement
Choose the relationship between the meta_query and what it's pulled into (AND/OR)
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Query | Version: | 3.4.1 |
| Severity: | normal | Keywords: | dev-feedback has-patch |
| Cc: |
Description
The use case for this is that I'd like to be able to, much like meta_query's "relation" option, be able to choose whether or not 'meta_query' itself should be treated like AND or OR in it's WHERE inclusion.
meta_query's "relation" option is already helpful, letting you treat any of the meta_query's arrays as OR instead of the default AND.
Adding this new option would provide the ability to treat meta_query as AND / OR based on the need of the WP_Query lookup.
Attachments (2)
Change History (6)
sc0ttkclark
— 10 months ago
comment:1
sc0ttkclark
— 10 months ago
- Keywords has-patch added
sc0ttkclark
— 10 months ago
comment:2
johnbillion
— 10 months ago
- Keywords reporter-feedback added
If you set the 'query_relation' parameter to OR in a given query, are you sure it has the desired effect? It will fetch anything at all which matches your meta query, regardless of any of the other arguments such as post type, post status, etc. I believe it will also affect any query parameter that comes after the meta query in the SQL due to the placement of the OR.
comment:3
sc0ttkclark
— 10 months ago
Actually you are correct @johnbillion, I was working on this solution for a friend who needed it to do as was explained, however there are flaws in it that make it more of an edge case. One main attraction to this is that even though it operates as you said - main arguments OR meta query match - it runs (sans filters) as the last of the 'where' clauses built out, so it's use isn't negated from what I explained above.
Here's an example:
$my_query = WP_Query( array( 'post_type' => 'any', 'cat' => 4, 'meta_query' => array( 'query_relation' => 'OR', array( 'key' => 'super_post', 'value' => 1 ) ) ) );
comment:4
sc0ttkclark
— 10 months ago
- Keywords reporter-feedback removed
Oops! Wrong patch selected the first time :)