Support

Account

Home Forums Front-end Issues Printing information from custom taxonomy

Solved

Printing information from custom taxonomy

  • Hello!

    I’ve been racking my brain and scouring forums for weeks to no avail, so I’m finally coming to the community for some help.

    I have a custom taxonomy called “game”, in this custom taxonomy I’ve created four ACF text fields, the issue I’m having is getting these text fields to print out the content within.

    Below is a shot of ACF, the custom taxonomy text fields, as well as the address bar for the custom taxonomy itself, and the URL for one of the custom taxonomy items.

    acffields

    n3customtax

    “…/wp-admin/edit-tags.php?taxonomy=game”

    “…/wp-admin/term.php?taxonomy=game&tag_ID=11113&post_type=post”

    Now, I’ve tried the following code:

    <?php echo the_field('game_publisher'); ?>

    This has worked with another set of fields I created, though these appear within a post, not a custom taxonomy.

    I’ve read through all of the tutorials, but I unfortunately have little understanding on how these work. Any help would be greatly appreciated.

  • Are you using ACF 4 or 5?

    In either case you need to supply the correct post ID value. In ACF for this is "{$taonomy}_{$term_id}". In ACF 5 you can use the same value or you can use "term_{$term_id}"

    In a tax archive template you can get the term ID like this

    
    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    

    To get the field you should either use

    
    // the_field() echos the value and you do not need to include your own echo statement
    the_field('game_publisher', $taxonomy.'_'.$term_id);
    

    or

    
    echo get_field('game_publisher', $taxonomy.'_'.$term_id);
    

    for more information see https://www.advancedcustomfields.com/resources/get_field/ Get a value from different objects

  • Hey John,

    We’re using Advanced Custom Fields 4.4.11.

    However, entering the code you supplied worked like a charm:

    <?php 
    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    // the_field() echos the value and you do not need to include your own echo statement
    the_field('game_publisher', $taxonomy.'_'.$term_id);
    ?>

    Thank you!

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

The topic ‘Printing information from custom taxonomy’ is closed to new replies.