WordPress advanced custom field query giving wrong results

I have the following code. It is supposed to return only the post from ‘portfolio’ custom post type where the format is ‘print’, the checkbox for ‘welcome_gallery’ is checked and the ‘market’ value is ‘italy’. But it returns also other post not matching these key values.

    $recent_posts = array(
        'post_type'  => 'portfolio', 
        'numberposts' => 8,
        'orderby' => 'rand',
        'meta_query'     => array(
            'relation' => 'AND',
            array(
                'meta_key'     => 'format',
                'meta_value'   => '%print&',
                'compare' => 'LIKE'
            ),
            array(
                'meta_key'     => 'welcome_gallery',
                'meta_value'   => '1',
                'compare' => '='
            ),
            array(
                'meta_key'     => 'market',
                'meta_value'   => '%italy%',
                'compare' => 'LIKE'
            )
        )
    );
    $the_query = new WP_Query( $recent_posts );

I’ve tried hard to make it work but it doesn’t. Before I get crazy, is there someone who can help me to undestand the reason?
Thanks in advance.

Read more here: WordPress advanced custom field query giving wrong results

Leave a Reply

Your email address will not be published. Required fields are marked *