Support » How-To and Troubleshooting » How to get all posts with a meta key?
5 years, 4 months ago
I have a group of data saved in post meta. One of the meta key is “project_id”, if a post meta has this key, that means this post include a project.
Now I want to get all post that with the meta key of “project_id”, so that I can make a loop for it.
I tried this
$meta_key = 'project_id';
return $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key));
It returns nothing.
Please help! Thanks!