What is the best way to create a meta query that searches through ALL meta fields (keys)? What I’m trying to do is something such as:

$posts = new WP_Query(array(
    'meta_query' => array(
        'relation' => 'OR'
        array(
            'key' => ALL,
            'value' => keyword
        )
    )
));

Does that make sense? What is the proper way of doing it?

Thanks

1 Answer
1

As @Howdy_McGee suggested and I made a quick test. Removing key do the trick so you can just remove the key and add compare LIKE if you do not want exact match.

Example:-

$posts = new WP_Query(array(
    'meta_query' => array(
        array(
            'value' => 'meta_value'
        )
    )
));

This will produce the SQL like

WHERE 1=1  AND ( CAST(wp_postmeta.meta_value AS CHAR) = 'meta_value' ) 

That is what we want!

Leave a Reply

Your email address will not be published. Required fields are marked *