I'd like to retrieve the post_id
from wp_post_meta
with a unique meta_key
and meta_value
. I've tried WP_Query
but no values are returned and I'm unable to retrieve the post_id
'
$post_query = new WP_Query( array(
'meta_key' => 'key',
'meta_value' => 'value',
'fields' => 'ids',
) );
$post_ids = wp_list_pluck( $post_query->posts, 'ID' );
return $post_ids;
A similar post on Stackoverflow suggests that the only way is using a SQL query which differs to the suggestion from Sally CJ.
Using a SQL query returns the post_id
. If possible, I'd like to use WP_Query
or a native function if there's one.