1

I have various custom taxonomy,

sometime, I have multiple choise selected in the back end ( cf screenshot)

enter image description here

however, in Front end, I have only one getting display, I would like to have all of them being display in front end . ..

This is the way I call them to display in front end:

  <?php
$taxonomy = wp_get_post_terms( $post->ID, 'category_job');
$locations = wp_get_post_terms( $post->ID, 'locations', array("fields" => "all"));
$types = wp_get_post_terms( $post->ID, 'types');
$sectors = wp_get_post_terms( $post->ID, 'sectors');
$salaries = wp_get_post_terms( $post->ID, 'salaries');
$price = wp_get_post_terms( $post->ID, 'price-range');
echo '<strong>Category:</strong> '.$taxonomy[0]->name.'<br>';
echo '<strong>Location:</strong> '.$locations[0]->name.'<br>';
echo '<strong>Sector:</strong> '.$sectors[0]->name.'<br>';
echo '<strong>Salary:</strong> '.$price[0]->name.'£'.'<br>';
echo '<strong>Type:</strong> '.$types[0]->name.'<br>';

?>

any help would be amazing :)

Thank you for your time guys !

1 Answer 1

0

add a loop to display all taxonomy :

if (2 > count($locations)) {
    echo '<strong>Location:</strong> '.$locations[0]->name.'<br>';
} else {

    echo "<strong>Location:</strong>";

    echo "<ul>";

    foreach ($locations as $l) {
        echo "<li>";
        echo $l->name;
        echo "</li>";
    }

    echo "</ul>";

}

.
other loop with all location on the same line

    $stack = array();

    foreach ($locations as $l) {
        $stack[] = $l->name;
    }

    echo "<strong>Location:</strong>" . implode(";", $stack) . "<br/>";
3
  • just a fast question, If i wish to add a coma ',' between each list, except the last one... how can i achieve this ? Thank you :)
    – tibewww
    Commented Aug 3, 2015 at 20:51
  • I edited my answer
    – mmm
    Commented Aug 3, 2015 at 20:55
  • arf, im sorry but i dont manage to see which part should i put it ... :( Im having a erorr message each time :(
    – tibewww
    Commented Aug 3, 2015 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.