1

I'm trying to include post meta in the scope of a WordPress search using WP_Query.

I have a meta query that looks like this:

$args['meta_query'] = [
    'relation' => 'AND',
    [
         'key' => 'quantity',
         'value' => 1,
         'compare' => '>='
    ],
    [
        'relation' => 'OR'
        [
            'key' => 'brand',
            'value' => 'bar'
        ],
        [
            'key' => 'vendor',
            'value' => 'biz'
        ]
    ]
]

When I add the 's' parameter to the query object, it seems like it's matching posts that have one of the meta query fields "brand" or "vendor", but also matches the description or title.

I want it to match like this: brand OR vendor OR title OR description.

The current semantics seem to be giving me something more like: (brand OR vendor) AND (title OR description)

  • What you want isn't possible just through just WP_Query arguments. You'd need to filter the SQL directly, with posts_where or posts_clauses. – Jacob Peattie Aug 29 '18 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.