Cannot filter posts by ACF relationship values

riyaz7us

riyaz7us

Posted on December 13, 2019

Cannot filter posts by ACF relationship values

The question belongs to Wordpress and Advanced Custom Fields.

I have created two post types i.e., 'courses' and 'universities'. In courses, I created a relationship 'related_university' that connects courses to universities. However, I could not filter my courses by relationship values (title or any other field).

the following method works for me when I print the title of the related university:

$result[] = array(
"id" => get_the_ID(),
"title" => get_the_title(),
"rel_university_name" => get_field("related_university")[0]->post_title,
);

However, I get no results when I use the same method to filter my posts by the title:

$args['meta_query'][] = array(
'key' => get_field('related_university')[0]->post_title,
'value' => $related_university_title,
'compare' => 'LIKE'
);

💖 💪 🙅 🚩
riyaz7us
riyaz7us

Posted on December 13, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related