[resolved] meta_query compare='!=' with multiple custom fields (2 posts)

  1. dilocker
    Posted 2 years ago #

    Hi everyone,

    a post has the following custom fields:

    'my_custom_field' => 1
    'my_custom_field' => 2
    'my_custom_field' => 3

    I now want to query all posts that do NOT contain the value 2 for 'my_custom_field'. I'm trying this:

    $args = Array('posts_per_page' => -1,
        'post_type' => 'page',
        'meta_query' => array(
            'key' => 'my_custom_field',
            'value' => 2,
            'compare' => '!='

    However, this is still returning my sample post, as my sample post has a field of 'my_custom_field' with a value other than 2 (1 and 3). I somehow need to change my query to say "Exclude posts that have at least one field of 'my_custom_field' with the value of 2".

    Can anyone help me? Thanks!

  2. dilocker
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic