loop query exclude meta_key with meta_value
-
Hi I use a loop like this:
// show all active coupons for this store and setup pagination $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts( array( 'post_type' => APP_POST_TYPE, 'post_status' => 'publish', APP_TAX_STORE => $term->slug, 'ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'paged' => $paged ) );now I have a meta value
meta_key' => 'clpr_excoupon'it is either 1 or 0.I would like to exclude all
meta_key' => 'clpr_excoupon'with'meta_value'=> 0,and ‘NOT EXISTS’ need help!!
-
Could you just query posts where the
clpr_excoupon=1?Rather than excluding the other values and posts that don’t have that key?
I did this:
// show all active coupons for this store and setup pagination $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts( array( 'post_type' => APP_POST_TYPE, 'post_status' => 'publish', APP_TAX_STORE => $term->slug, 'ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'clpr_excoupon', 'compare' => 'NOT EXISTS' ), array( 'key' => 'clpr_excoupon', 'compare' => '!=', 'value' => '1' ), ), 'paged' => $paged ) );and it is working…..
I could be reading it backwards, but that looks like the opposite of your original question.
Either way, I’m glad it’s working for you! 🙂
you right, my mistake, sorry english is not my first language, i wanted to exclude all post with value 1 😉
lol – don’t be sorry, I just thought I was crazy for a second there 😉
The topic ‘loop query exclude meta_key with meta_value’ is closed to new replies.