• Resolved Archie Makuwa

    (@archie22is)


    Hi guys,

    Just one more question today, how to I return multiple selected categories slugs in WordPress?

    I previously only required one category slug per post and I used the method below:

    $selected_cat = '';
    $work_cats = get_the_terms( $post->id, 'work_categories' );
    foreach ( $work_cats as $work_cat ) {
    	$selected_cat = $work_cat->slug;
    }

    I need to return all selected categories for that particular post and use them in a filter on the website.

Viewing 1 replies (of 1 total)
  • Thread Starter Archie Makuwa

    (@archie22is)

    Guys,

    I came right – sometimes I am amazed by my smartness:-) It was simply really:

    I started by getting the categories as follows:

    <?php
    while ($wp_query->have_posts()) : $wp_query->the_post();
    
    #get the terms
    $terms = get_the_terms( $post->ID, 'work_categories' ); 
    
    ?>

    In the li tag I simply looped though the selected categories and displayed them for the isotope to abuse – that easy. Now, that will be $50 – thank you very much!

    <li class="work_block <?php foreach( $terms as $term ) echo ' ' . $term->slug; ?>" ... </li>

Viewing 1 replies (of 1 total)
  • The topic ‘How do I return multiple selected categories slugs?’ is closed to new replies.