Forums

[resolved] List customy taxonomy terms associated with current post. (3 posts)

  1. dguyen
    Member
    Posted 1 year ago #

    Maybe I'm missing something. I truly apologize if this is been resolved before, but I could not find the solution.

    I want to list the terms for my custom taxonomy associated with each post. Currently I'm using:

    <?php echo $terms = get_the_term_list( $post->ID, 'skills'); ?>

    which works great, but the items are in a string. How can I put each term into a list item

    ... I tried the foreach but returns an invalid argument.

    Can anyone help shed some light? Thanks so much in advance.

  2. MAS
    Member
    Posted 1 year ago #

    check once get_term_by_slug() function. see on codex

  3. dguyen
    Member
    Posted 1 year ago #

    So far I've decided to separate the terms with a comma, then exploding the terms and include a foreach statement.

    <?php get_the_term_list( $post->ID, 'skills', '', ', ');
    $skills = explode(',',get_the_term_list( $post->ID, 'skills-proficiencies', '', ', '));
    foreach ($skills as $skill) { ?>
    <li><?php echo $skill; ?></li>
    <?php } ?>

    Someone please let me know if there's a better solution.

Topic Closed

This topic has been closed to new replies.

About this Topic