• Resolved joloshop

    (@joloshop)


    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!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Chad

    (@lynneandchad)

    Could you just query posts where the clpr_excoupon=1?

    Rather than excluding the other values and posts that don’t have that key?

    Thread Starter joloshop

    (@joloshop)

    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…..

    Chad

    (@lynneandchad)

    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! ??

    Thread Starter joloshop

    (@joloshop)

    you right, my mistake, sorry english is not my first language, i wanted to exclude all post with value 1 ??

    Chad

    (@lynneandchad)

    lol – don’t be sorry, I just thought I was crazy for a second there ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘loop query exclude meta_key with meta_value’ is closed to new replies.