user3220407
user3220407

Reputation: 41

Post id by metadata

Hellow guys i have seen a php code which is realted to post id metadata in wordpress.

The code is

global $wpdb;

$results = $wpdb->get_results( "select post_id, meta_key from $wpdb->postmeta where meta_value = 'this is my example value.'", ARRAY_A );

I just need to know from where $wpdb->postmeta came from ?..is it applicable to use like this . how the meta_key and post_id is retrieved from$wpdb->postmeta ..i havnt seen a variable declaired like $postmeta .

Any help would be appreciated

Upvotes: 0

Views: 130

Answers (1)

Beardminator
Beardminator

Reputation: 774

$Wpdb->postmeta is a constant which is holding the name of the postmeta table of wordpress sql. It's "wp_postmeta" by default. (If you chosen the "wp" db prefix.)

WP_Postmeta DB contains the following rows:

meta_id
post_id
meta_key
meta_value

You are searching in that query by "meta_value". The query will give back all rows meta_id and post_id where the meta value is equal to "this is my example value".

Wordpress stores attributes to posts, this is what "wp_postmeta" is. So it needs to store which post does it belong to.

Upvotes: 1

Related Questions