Forums

meta_query using NOT IN (2 posts)

  1. Briteweb
    Member
    Posted 10 months ago #

    I'm trying to use query_posts to fetch posts, excluding those with custom field values that are in a provided array.

    Here is the meta_query part of query_posts that I am using:

    array( array( 'key' => 'special', 'value' => array( 'val1', 'val2', 'val3' ), 'compare' => 'NOT IN' ) )

    To clarify, I want to fetch all posts, except those that have val1, val2 and/or val3 as 'special' meta values. In theory this meta_query code work, but it is still fetching posts that have the specified meta values.

    Would really appreciate any insight into why this isn't working!

    Thanks!!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 10 months ago #

    What about:

    $args = array(
    	'meta_query' => array(
    		array(
    			'key' => 'special',
    			'value' => 'val1',
    			'compare' => 'NOT LIKE'
    		),
    		array(
    			'key' => 'special',
    			'value' => 'val2',
    			'compare' => 'NOT LIKE'
    		),
    		array(
    			'key' => 'special',
    			'value' => 'val3',
    			'compare' => 'NOT LIKE'
    		)
    	)
     );

Reply

You must log in to post.

About this Topic