How do I select a post by its metadata found in the wp_postmeta
table? Preferably using ElasticPress.
new WP_Query( array(
's' => 'meta search phrase',
'search_fields' => array(
'post_title',
'post_content',
'post_excerpt',
'meta' => array( 'meta_key_1', 'meta_key_2' ),
),
) );
I found this example from the ElasticPress documentation, but I am not sure that this is querying the correct table (wp_postmeta), and I also want to check if a particular value is in post meta value, not the post meta key...
EDIT:
I've tried this below, but am not getting anything returned with this query. I'm setting 'key' => 'foo_listing_syndication',
and 'value' => $term,
where $term
is the search text and foo_listing_syndication
is the key in the meta_key
column of the wp_postmeta
table. Would this not be correct? See screenshot of the wp_postmeta
table. The $term
I am trying to search for is found the in meta_value
column.
$query = new \WP_Query([
...
's' => $term,
'meta_query' => array(
array(
'key' => 'foo_listing_syndication',
'value' => $term,
'compare' => '=',
),
),
]);