Home Forums Backend Issues (wp-admin) How to display dynamicly ACF Fields on change Taxonomy in post-edit ?


How to display dynamicly ACF Fields on change Taxonomy in post-edit ?

  • Hi

    I create my custom post_type “team”, and taxonomy for it “team_category”, and ACF Fields group – team_type.
    Next I create 2 taxonomy term – for example: team_type_1, team_type_2 (slug).
    I want show my ACF Field Group when User set my taxonomy on team_type_1 – so I create functions and all working, but i have one problem… The fields group load only when post have that term – when i create new post, i dont see Fields, i must set my taxonomy on team_type_1, and click “submit”, all working, but after page reload.

    Can you have any ideas, how fix it for load and show my Fields dynamicly?
    I find few examples, but nothing happens…

    add_filter('acf/location/rule_match/team_type', 'acf_location_rules_match_team_type', 10, 3);
    function acf_location_rules_match_team_type($match, $rule, $options){
        $media_tax_slug = 'team_category';
        if( empty($options['post_id']) ){
            return false;
            $main_post_cat = noir_get_team_term($options['post_id'], "team_category", 'slug'); 
            //now $main_post_cat has my team_category object for this post
            if( $rule['value'] == $main_post_cat->term_id ){
                return TRUE;
                return FALSE;
  • the problem is that you are looking at the actual term currently set for the post that is stored by WP.

     $main_post_cat = noir_get_team_term($options['post_id'], "team_category", 'slug'); 

    You need to look at this, but you also need to check to see if ACF has included the currently selected therm in the $options that it is passing to the filter. This is actually more important then testing the posts current terms, but you need to do both, first checking the $options and if it is not set or it is empty then checking against the post’s current terms.

    If nothing has changed since the last time I created a custom location rule then the terms selected will be in $options['taxonomy']

    One of my old examples shows this

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

You must be logged in to reply to this topic.