WP_Meta_Query – I have to have OR, not AND

So I am battling with WP_Meta_Question. I require an “OR” – not an “AND” and the docs/Google/StackExchange aren’t aiding. I have set way way too a lot of hrs into this, so I believed I would question in this article.

I have obtained a purpose established up in my capabilities.php file that I phone like this:

insert_action( ‘pre_get_posts’, ‘my_meta_query’ )

So significantly, so great. My Meta Question array values glance like this:

meta_query: Array (
[relation] => OR
[0] => Array
(
[key] => var_product
[value] => 9190
[compare] => LIKE
)

[1] => Array
(
[key] => _sku
[value] => 9190
[compare] => LIKE
)

)

The Query Observe plugin shows this:

Find SQL_CALC_Observed_ROWS chlt_posts.ID
FROM chlt_posts
Inner Be a part of chlt_postmeta
ON ( chlt_posts.ID = chlt_postmeta.put up_id )
Exactly where 1=1
AND ( chlt_posts.ID NOT IN (
Find object_id
FROM chlt_phrase_relationships
The place time period_taxonomy_id IN (6,9) ) )
AND (((chlt_posts.put up_title LIKE ‘%9190%’)
OR (chlt_posts.put up_excerpt LIKE ‘%9190%’)
OR (chlt_posts.put up_written content LIKE ‘%9190%’)))
AND ( ( chlt_postmeta.meta_key = ‘var_item’
AND chlt_postmeta.meta_worth LIKE ‘%9190%’ )
OR ( chlt_postmeta.meta_essential = ‘_sku’
AND chlt_postmeta.meta_worth LIKE ‘%9190%’ ) )
AND ((chlt_posts.submit_type = ‘product’
AND (chlt_posts.post_status = ‘publish’
OR chlt_posts.post_position = ‘private’)))
Group BY chlt_posts.ID
Buy BY chlt_posts.put up_title LIKE ‘%9190%’ DESC, chlt_posts.post_date DESC
Restrict , 12

If I operate that question in the SQL tab of PhpMyAdmin, it returns zero effects.

But if in PhpMyAdmin I transform this line …

AND ( ( chlt_postmeta.meta_essential = ‘var_item’

… to …

OR ( ( chlt_postmeta.meta_key = ‘var_item’

… I then get the correct outcomes.

Docs/Google/StackExchange inform me that the “[relation] => OR” really should fix this. But it isn’t going to.

Does any person know how to “append” the Meta Question working with an “OR” as an alternative of an “AND”???

Thanks in advance!

Leave a Reply

Your email address will not be published.