WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hello this is my query. I want to show the titles of posts that have fullfil the following but it doesn't show anything, I don't know. Thank you! Also, is there another way to show the results, more wordpress-like?


$theposts = $wpdb->get_results("SELECT post_title FROM $wpdb->posts
   FROM $wpdb->postmeta
   WHERE meta_key = 'extra1' AND meta_value = 'test'

foreach ($theposts as $thepost) {
echo $thepost->post_title;

share|improve this question

You need to use WordPress meta query:

Display posts where the custom field key is 'extra1' and the custom field value is 'test':

$query = new WP_Query( array( 'meta_key' => 'extra1', 'meta_value' => 'test' ) );

For more info take a look at WP Query Custom_Field_Parameters.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.