Support

Account

Home Forums Backend Issues (wp-admin) use get_field() inside acf/fields/taxonomy/query/ filter

Solving

use get_field() inside acf/fields/taxonomy/query/ filter

  • Hi !
    Is it possible to use get_field() inside acf/fields/taxonomy/query/ filter ?
    I try to get the value from an other field from the filter function but it’s seems that what is return is null. The get_filed() function works well outside of this filter. Also how can i debug my variable inside the acf/fields/taxonomy/query/ filter ? When i use var_dump or echo inside the filter, it prevent the filter function from working.

    
    function custom_acf_taxonomy_filter( $args, $field, $post_id ){
        $parent = get_field('field_5f326eac0b9d8', false);
        $args['parent'] = $parent->term_id;
        return $args;
    }
    add_filter('acf/fields/taxonomy/query/key=field_5f32a57681da9', 'custom_acf_taxonomy_filter',11,3);
    

    Thanks a lot for your help

  • Hi there, did you manage to solve this ?
    I’ve a similar problem with using this filter 🙁

  • You must supply the post ID

    If it is the same post and the field is already saved

    
    $parent = get_field('field_5f326eac0b9d8', $post_id);
    

    Otherwise look at this topic https://support.advancedcustomfields.com/forums/topic/filter-post-object-based-on-selected-taxonomy/

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.