0

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

<div id="new_on">

            <?php 
            $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(); ?>

            </div>

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?

1 Answer 1

1

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(
                array(
                    'key' => 'is_url', 
                    'value' => 'yes', 
                    'compare' => 'NOT LIKE'
                )
            ),
        );
1
  • 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
    Commented Aug 21, 2011 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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