danyo
danyo

Reputation: 5856

wordpress get post_id where meta_value =

I am trying to query the wordpress post_meta table by meta_value.

I would like to output all post_id's where the meta_value is = to _parent_product. Here is my code:

$posts = $wpdb->get_results("SELECT *, FROM $table WHERE meta_key='_parent_product' ");
foreach ( $posts as $post ){

$id = $post->post_id;

echo $id;

}

The above outputs nothing and im not quite sure why? Can anyone see anything wrong?

Upvotes: 0

Views: 1290

Answers (1)

dbf
dbf

Reputation: 3463

As stated in the comment,

There is a comma (,) behind SELECT *,. Therefor the given SQL is invalid and will fail to retrieve any results.

Upvotes: 1

Related Questions