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
);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.