WordPress meta_query to compare 3 meta value with same meta key

I would like to fetch all post that have meta_value Book, Study, Art. But when I put 3 array on meta_query system doesn’t return anything, but if I put online 2 array It’s work

// this working
     $args = array(
    'numberposts' => 10,
    'post_type' => 'content',
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'media_type',
            'value' => 'Book',
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'media_type',
            'value' => 'Study',
            'compare' => 'LIKE'
        )       
    )
);


//this now working
 $args = array(
    'numberposts' => 10,
    'post_type' => 'content',
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'media_type',
            'value' => 'Book',
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'media_type',
            'value' => 'Study',
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'media_type',
            'value' => 'Art',
            'compare' => 'LIKE'
        )
    )
);

Related posts

Leave a Reply

1 comment

  1. It sounds like you are searching for the exact meta values, so did you try:

    $args = array(
         'posts_per_page' => 10,
         'post_type'      => 'content',
         'meta_query'     => array(
                array(
                    'key'     => 'media_type',
                    'value'   => array( 'Art', 'Book','Study' ),
                    'compare' => 'IN'
                ),
          ),
    );
    

    as your query arguments?

    Sidenote: The parameter numberposts works, but posts_per_page is now more commonly used in WP_Query().