I have a working query that calls all my posts that have a certain meta value for one of two meta keys:

$term = filter_var( $_GET['term'] );
$query = get_posts( [
    'post_type' => 'some_cpt_name',
    'meta_query' => [
        'relation'      => 'OR',
        [
            'key'     => 'foo',
            'value'   => $term,
            'compare' => 'LIKE',
        ],
        [
            'key'     => 'bar',
            'value'   => $term,
            'compare' => 'LIKE',
        ],
    ]
] );

I need to query all posts that have the $term as meta key “foo” or “bar” or as post title. Problem is how to add the post title as additional possible key?

Q: How can I also check if the $term maybe is in the post_title?

2 Answers
2

As with most questions involving OR clauses, the answer is the same: use a custom query or alter WP_Query using the 'posts_clauses' filter.

Leave a Reply

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