• Resolved formica

    (@formica)


    Hi there

    Possibly a strange question but I have myself in a muddle with taxonomies. And need to output a list of terms from a taxonomy:

    echo get_the_term_list( $post->ID, 'therapies', '', '<br />', '' );

    Works perfectly, but it links to the taxonomy page and I need it to link to a single.php post ie.

    it links to here:
    website/therapies/physiotherapy/

    and i need it to link to here:
    website/physiotherapy/

    Anyone know a way to change the ‘get_the_term_list’ or to dynamically redirect the taxonomy page to the single?

    Many thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter formica

    (@formica)

    Ooohh… it’s ugly and ‘technically’ doesn’t work but a preg_replace removes the taxonomy term in the url

    $terms = get_the_term_list( $post->ID, 'therapies' );
      $terms = preg_replace('/\btherapies\b/ie', ' ', $terms);
      // This will remove the word 'therapies'
      echo $terms;

    It removes the word but leaves the forward slash. I’m thinking strip_tags may remove the slash?! but wordpress kindly removes it anyway, so it works for now.

    If anyone knows a cleaner way of doing this please let me know.

    Thanks

    why don’t you strip terms using strip_tags() function

    $terms = strip_tags(get_the_term_list( $post->ID, 'therapies', '', '/' );
    $terms = explode("/",$terms)'
    for($i=0; $i<count($terms); $i++){
      echo "<a href='your-own-url/$terms[$i]'>" . $terms[$i] . "</a><br />";
    }
    Thread Starter formica

    (@formica)

    Genius! Thanks Husdaman. Much better than my solution.

    No problem, glad it helped.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Taxonomy 'get_the_term_list' redirect’ is closed to new replies.