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

I've got the following loop on my index.php template:

<div id="new_on">

            $args = array( 
                'meta_query' => array(
                    'meta_key' => 'is_url', 
                    'meta_value' => 'yes', 
                    'meta_compare' => 'NOT LIKE'

            $main_query = new WP_Query( $args );
            while ( $main_query->have_posts() ) : $main_query->the_post();

            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <div class="clearfix smalltext"><span class="left"><a href="<?php the_author_link(); ?>"><?php the_author(); ?></a></span><span class="right"><?php echo the_time(); ?></span></div>
            <?php the_excerpt(); ?>

            <?php endwhile; wp_reset_postdata(); ?>


The query should return all posts that do not have the custom field 'is_url' set to 'yes'. It is returning all posts, regardless of the value of is_url. I usually use Custom Post Types for this sort of thing, so I haven't used the meta_query too extensively. Anybody know what I'm doing wrong?

share|improve this question
up vote 1 down vote accepted

I think you're using wrong keys for meta_query array, also it expects nested arrays, even if you only have one query. Code below should help.

        $args = array( 
            'meta_query' => array(
                    'key' => 'is_url', 
                    'value' => 'yes', 
                    'compare' => 'NOT LIKE'
share|improve this answer
There's a way to do the query without the meta_query parameter. I had the right params for that. But I changed over to the meta_query method. Confusing design. Thanks for your help. – jdp Aug 21 '11 at 21:29

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.