Support

Account

Home Forums Front-end Issues Show custom taxonomy on custom post type page

Solved

Show custom taxonomy on custom post type page

  • Hi all,

    Would love some help on a website I’m currently building because I seem to not get something to work. The website has a custom post type ‘evenement‘. I have created a custom taxonomy ‘locatie‘ and last but not least I have made a Field group item ‘evenement_locatie‘, linked to the custom taxonomy.

    I made a template for that show’s a single evenement post, that show’s the custom fields which I get with this code


    <p><?php the_field("event_startdate"); ?><br> om <?php the_field("event_starttime"); ?></p>

    This works fine for all fields, however I can’t seem to load the custom taxomony, and I tried all codes that I could find online. This is the code I’m currently using:

    <?php
    $term = get_field('evenement_locatie'); if( $term ): ?> <h2><?php echo esc_html( $term->name ); ?>test</h2> <p><?php echo esc_html( $term->description ); ?></p> <?php endif; ?>

    And I have also tried


    <?php echo get_field('evenement_locatie', get_queried_object()); ?>

    Also tried to use the get_term function, but I can’t figure out how to get it working.
    I also trying using get_field(‘locatie’) and that does not work as well.

    My goal is to show the taxonomy title, and the description, but I’ve tried for hours now to get something. Also the WP_DEBUG is not giving me any error’s as well, so don’t know how to continue.

    Any tips or tricks?
    Thanks in advance!

  • Someone on StackOverflow helped me out! This is the answer

    <?php
    $terms = get_the_terms(get_the_ID(), 'locatie'); // Get the terms associated with the post
    if ($terms && !is_wp_error($terms)) :
        foreach ($terms as $term) : ?>
            <h2><?php echo esc_html($term->name); ?></h2>
            <p><?php echo esc_html($term->description); ?></p>
        <?php endforeach;
    endif;
    ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.