Support

Account

Home Forums General Issues Get Advanced Custom Field Group for specific taxonomy term

Solved

Get Advanced Custom Field Group for specific taxonomy term

  • As the question states I’m trying to get an Advanced Custom Field Group for specific taxonomy term it’s been assigned to. I’ve come across

    acf_get_field_groups();
    Easy enough to get a group from a post ID and also from a taxonomy but when trying to get it for a term I’m having no luck;

    Tried these(just guessing):

    acf_get_field_groups(array('term_id' => '1293'));

    acf_get_field_groups(array('taxonomy' => 'services','term_id' => '1293'));
    I’m nt sure if this function is capable of doing wha I’m asking either it’s not or else I just am not providing the argument format correctly.

  • Generally, a group is assigned to a taxonomy, which means all of the terms in that taxonomy and not to a specific term.

  • Ok so I’m actually talking about a acf Group that is assigned to a post if the taxonomy term is equal to a specific term. Using:

    acf_get_field_groups(array('taxonomy' => 'services');

    I am able to get acf groups assigned to a taxonomy but I want to apply different acf groups(services) to different customs posts(adverts). I can assign the group so when I check a term the relevant acf group meta box appears but I have been unable to get specific groups on the front end.

  • I am not 100% certain how acf_get_field_groups() works, but I have used it before. If you use the post_id argument

    
    acf_get_field_groups(array('post_id' => '1293'));
    

    and ACF filters the groups returned based on location rules, and the term is assigned to that post, then is should return the group that used when the term is selected.

    But again, not 100% certain on that as I do not know if location rules effect the results.

  • Thanksfor your reply I’ve come across that before but that will get me all of the field groups assigned to a post/page/cpt etc I’m looking for the groups assigned to a term. So that why I was guessing at thing like this.

    acf_get_field_groups(array('term_id' => '1293'));

  • You are confusing me because you said above that you want the fields of a post assigned to a term.

    Ok so I’m actually talking about a acf Group that is assigned to a post if the taxonomy term is equal to a specific term.

    But you are also asking about getting fields shown for a term.

    I’m looking for the groups assigned to a term.

    This would be like the fields that might be displayed on a page such as

    /wp-admin/term.php?taxonomy=category&tag_ID=1&post_type=post

    These are two completely different things.

    for the first I would use
    acf_get_field_groups(array('post_id' => '1293'));
    for the second I would try
    acf_get_field_groups(array('post_id' => 'term_1293'));

  • SORRY THIS IS NOT SOLVED I CLICKED IT BY MISTAKE AND CAN’T UNDO

    Ok so I’m actually talking about a acf Group that is assigned to a post if the taxonomy term is equal to a specific term.

    Sorry just reading that back, it doesn’t make a lot of sense (if I was able to upload a screengrab initially this would’ve been easier)

    The specific term is what I’m looking for not post. What I meant above is that when I assign a field group to a term i.e. in the acf group location meta box I’m setting:

    Show this field group if Post Taxomony is equal Term(e.g. Web Design)

    This is a custom taxonomy(Services) for a custom post type(Deals) and if I open a Post/Service and set the taxonomy term to Web Design then my field group appears.

    So I’m looking to get the field group that is assigned to Web Design

    This is along the lines of what I was trying but is returning an empty array.
    acf_get_field_groups(array('post_id' => 'term_1293'));

    Sorry for the confusion.

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

The topic ‘Get Advanced Custom Field Group for specific taxonomy term’ is closed to new replies.