Home Forums ACF PRO Taxonomy Terms


Taxonomy Terms

  • I want to offer content authors the ability to select Tags that I will show in the page.

    I have a layout that has a field called “resources_carousel_topic_filter_list”. The field type is “Taxonomy Terms” and I have the Allow Taxonomy to only allow “Tags” as a horizontal row of checkboxes.

    When editing the page, it looks as expected. I can select several tags.

    However, I’m having trouble displaying these selected tags. I can see that ‘resources_carousel_topic_filter_list’ “has rows”, but I cannot get the selected tags.

    while ( have_rows( 'resources_carousel_topic_filter_list' ) ) : the_row();
            // i can get here if I put a breakpoint

    get_field( 'resources_carousel_topic_filter_list' ) returns null as does
    get_sub_field( 'resources_carousel_topic_filter_list' )

  • I guess I’m a newbie and didn’t realize that in a while loop you can run a get_row() to get the value of each loop.

    I found that when set to Taxonomy Terms and despite setting the “Return Value” to “Term object” get_row() only returns the term id. ( I guess I should change this back to ‘Term Id’ in case ACF fixes this bug in the future.)

    So I have to also run get_term($termid)

    Final result:

    $terms   = [];
    while ( have_rows( 'resources_carousel_topic_filter_list' ) ) : the_row();
       $terms[] = get_term(get_row());
    echo "<pre>\n";
    var_dump( $terms );
    echo "</pre>\n";
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.