• Resolved Marco Galasso

    (@marco_teethgrinder)


    Hello,

    I have a custom post type with 3 custom taxonomies “alpha”, “beta” and “gamma”.

    I need to outuput the terms belonging to each taxonomy as classes for an unordered list.
    I mean

    <ul>
    <li class="alpha's term(s) beta's term(s) gamma's therm(s)">lorem ipsum</li>
    <li class="alpha's term(s) beta's term(s) gamma's therm(s)">lorem ipsum</li>
    <li class="alpha's term(s) beta's term(s) gamma's therm(s)">lorem ipsum</li>
    </ul>

    Is there a quick way to do it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think that get_terms() can do what you want:

    $terms = get_terms(array('alpha','beta','gamma'));
    foreach ($terms as $term) {
       $classes .= $term->slug . ' ';
    }

    Then your li items will use $classes as the class list. It will not be in order by taxonomy, but in a list of classes this should not matter.

    Thread Starter Marco Galasso

    (@marco_teethgrinder)

    hello, I used wp_get_object_terms()

    <li class="all <?php
    $specialties_tax = (array('alpha','beta','gamma'));
    $specialties_terms = wp_get_object_terms($post->ID, $specialties_tax, $args);
    if(!empty($specialties_terms)){
    if(!is_wp_error( $specialties_terms )){
    foreach($specialties_terms as $term){
    echo ' '.$term->name.' ';
    }
    }
    }
    ?>">

    Now the next step is to make them filterable via a jQuery script.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom taxonomies terms as unordered list li classes’ is closed to new replies.