WordPress.org

Forums

meta_query using NOT IN (2 posts)

  1. Briteweb
    Member
    Posted 3 years 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
    Forum Moderator
    Posted 3 years 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'
    		)
    	)
     );

Topic Closed

This topic has been closed to new replies.

About this Topic