0

this might be a simple question but I just can't get my hands around it.

I have a WP_query listing of custom post type in wordpress, and I need to have an appropriate taxonomies (categories) displayed for each one of those items in the list.

I tried googling and searching through stackoverflow but came up short.

Also, this is what I'm using for displaying all the taxonomy slugs that exist for a certain post type:

function get_taxonomy_classes($theID) {

        $post_type  = get_post_type($theID);
        $taxonomies = get_object_taxonomies($post_type, 'objects');

        $terms = get_terms($taxonomies, array(
            'orderby' => 'name',
            'order' => 'ASC',
            'hide_empty' => TRUE
        ));
        foreach($terms as $term) {
            echo $term->slug . " ";
        }

    }

Still haven't found a way to use those terms with taxonomies above :(

Please help, thank you!

Slavisa Perisic
  • 1,110
  • 3
  • 18
  • 32

1 Answers1

1

Nevermind, guys. I found an answer myself.

It's pretty simple, you just need wp_get_object_terms() function

   $termss = wp_get_object_terms(get_the_ID(), 'portfolio_category');
   foreach ($termss as $term) {
      echo $term->slug;
   }
Slavisa Perisic
  • 1,110
  • 3
  • 18
  • 32