Home › Forums › General Issues › Custom rule for any term within a taxonomy › Reply To: Custom rule for any term within a taxonomy
This is my matching function. It functions correctly but only on page load. Is anyone able to suggest how to get custom taxonomy terms into the $options array so the function can evaluated on changes to the custom taxonomy.
function acf_location_rules_match_taxonomyTerm( $match, $rule, $options ){
// vars
$taxonomies = get_object_taxonomies( $options['post_type'] );
$terms = $options['taxonomy'];
// not AJAX
if( !$options['ajax'] ){
// no terms? Load them from the post_id
if( empty($terms) ){
if( is_array($taxonomies) ){
foreach( $taxonomies as $tax ){
$all_terms = get_the_terms( $options['post_id'], $tax );
if($all_terms){
foreach($all_terms as $all_term){
$terms[] = $all_term->term_id;
}
}
}
}
}
if($rule['operator'] == "<==>"){
$match = false;
if($terms){
$current_terms = get_the_terms($options['post_id'], $rule['value']);
if ( $current_terms && ! is_wp_error( $terms ) ) {
$current_term_ids = array();
foreach ($current_terms as $current_term) {
$current_term_ids[] = $current_term->term_id;
}
}
foreach ($current_term_ids as $current_term_id) {
if( in_array($current_term_id, $terms) ){
$match = true;
}
}
}
}
else{
$match = false;
}
}
return $match;
}
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.