wpdb – Is there another way to retrieve a post_id from post_meta other than a SQL query?
Question
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.
0
2 weeks
2023-05-12T19:02:43-05:00
2023-05-12T19:02:43-05:00 0 Answers
0 views
0
Leave an answer