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

For some reason. I do not have the ability to query by meta_key when I run a loop. What could cause this and what can I do to the diagnose the problem? I am using wordpress 3.4.1.

$args = array( 'meta_key' => 'slideshow_image');

$query = new WP_Query($args);
share|improve this question
You've specified the meta_key, but what are you trying to actually search for? If you're trying to return any post which has that meta_key in use, try adding these keys to your $args array: 'value' => array(''), 'compare' => 'NOT IN' – dunc Jul 19 '12 at 20:30
up vote 2 down vote accepted

Thanks for @dunc and @helgatheviking I got the answer. Here's my code. You need the post type declared, otherwise it resorts to "post". I also couldn't do this unless I put meta_key and meta_value in a 'meta_query' multidimensional array.

$args = array(
         'post_type'    => 'tsa_events',
         'meta_query'   => array(
               'key'          => 'slideshow_image',
               'value'    => array(''),
               'compare'  => 'NOT IN'


EDIT: you can also structure your query this way:

$args = array(
         'post_type'     => 'tsa_events',
         'meta_key'      => 'slideshow_image',
         'meta_value'    => array(''),
         'meta_compare'  => 'NOT IN'
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.