php - Get categories for a single post in a custom post type -


i'm trying unformatted list (preferably list of slugs) of categories single post in custom post type loop. list serve class div ($categoryslugswilleventuallygohere).

i've found few different methods of getting list of of categories custom post type, not ones specific single one. here's have far:

<?php $projects_loop = new wp_query( array( 'post_type' => 'projects', 'orderby' => 'menu_order' ) ); ?>                          <?php while ( $projects_loop->have_posts() ) : $projects_loop->the_post(); ?>                               <div class="box <?php $categoryslugswilleventuallygohere; ?>">                                      <div class="port-item-home">                                         <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'portfolio-home' ); ?></a>                                         <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>                                     </div>                                  </div>                        <?php endwhile; ?> 

and here's i've tried far category list:

<?php                                     $args = array(                                       'orderby' => 'name',                                       'parent' => 0,                                       'taxonomy' => 'project-type'                                       );                                     $categories = get_categories( $args );                                      echo '<p> '.print_r(array_values($categories)).'something</p>'                                  ?> 

i have returning array - array showing it'll display categories instead of ones pertaining specific post.

i tried:

<?php     //list terms in given taxonomy (useful widget twentyten)         $taxonomy = 'project-type';         $tax_terms = get_terms($taxonomy); ?>  <?php     foreach ($tax_terms $tax_term) {         echo $tax_term->name;     } ?> 

and displays categories instead of ones pertaining post.

any suggestions??

got it! found article helped me out:

https://wordpress.org/support/topic/how-to-get-the-category-name-for-a-custom-post-type

<!-- query --> <?php      $args = array(          'post_type'      => 'my_post_type',          'posts_per_page' => -1,          'orderby'        => 'menu_order' );      $custom_query = new wp_query( $args ); ?>  <!-- loop --> <?php      while ( $custom_query->have_posts() ) :          $custom_query->the_post();         $terms_slugs_string = '';         $terms = get_the_terms( $post->id, 'my_post_type' );         if ( $terms && ! is_wp_error( $terms ) ) {                             $term_slugs_array = array();             foreach ( $terms $term ) {                 $term_slugs_array[] = $term->slug;             }             $terms_slugs_string = join( " ", $term_slugs_array );         } ?>      <div class="box<?php echo $terms_slugs_string ?>">                   <div class="port-item-home">             <a href="<?php the_permalink(); ?>">                 <?php the_post_thumbnail( 'portfolio-home' ); ?>             </a>             <a href="<?php the_permalink(); ?>">                 <?php the_title(); ?>             </a>         </div>     </div>    <?php endwhile; ?> 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -