I see, guess it’s not as simple as it looked.
I really appreciate your help.
Will post a solution if I get there
My working code filters Courses bases on $post_id of the School taxonomy, however in a case that involves repeaters $post_id would be an ID of my Blog post (as I understand).
Is it possible to dynamically access the properties of School taxonomy inside of the repeater and if it is – how?
Wouldn’t that filter a single post_object field ?
I basically want to filter each ‘Courses’ post object field by the corresponding ‘School’ taxonomy field
Attached the image of my repeater structure. In my blog post I have (let’s say) 15 schools
This is what worked for filtering inside the Taxonomy Term Editor ( no repeater )
add_filter('acf/fields/post_object/query/name=courses_list', 'filter_by_category');
function filter_by_category( $args, $field, $post_id ) {
// $post_id comes in here as term_# so we need to remove 'term_' to get the term ID
$prefix = 'term_';
// Also if you are creating a new taxonomy, post_id = 'term_0' so then there's no point in adding a filter
if ( 'term_0' != $post_id && substr( $post_id, 0, strlen( $prefix )) == $prefix ) {
// Set $term_id to the ID part of $post_id
$term_id = substr( $post_id, strlen( $prefix ) );
// And adjust the query to filter by specific taxonomy term
$args['tax_query'] = array(
array(
'taxonomy' => 'school',
'field' => 'term_id',
'terms' => array($term_id),
),
);
}
return $args;
}
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.