Support

Account

Home Forums General Issues Query post with get_field() Reply To: Query post with get_field()

  • Select fields are saved as serialized arrays. That means that this

    
    $categoria = get_field( "categorias" );
    

    will return an array and you want to search for other posts that contain one of the values in the array. What you need is something like this

    
    $categoria = get_field( "categorias" );
    
    $meta_query = array('relation' => 'OR');
    if ($categoria) {
    	foreach ($categoria as $value) {
    		$meta_query[] = array(
    		  'key' => 'categorias',
    			'value' => '"'.$value.'"',
    			'compare'	=> 'LIKE'
    		);
    	}
    }
    
    // args
    $args = array(
    	'numberposts'	=> -1,
    	'post_type'		=> 'playlists',
    	'meta_query'	=> $meta_query
    );