Title: get post&#039;s categories as simple text
Last modified: August 20, 2016

---

# get post's categories as simple text

 *  Resolved [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/)
 * I want to get the current post’s categories (most of my posts
    are in multiple
   categories) as simple text, separated by commas like that: movies, articles, 
   photos, but when the post is only in one category I want only this category’s
   name with no comma like that: movies
 * I would really appreciate if someone knows how to that because
    I tried playing
   with the wp_list_categories and get_categories but could not get it right…
 * Thank’s!

Viewing 13 replies - 1 through 13 (of 13 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709476)
 * Something like `<?php the_category(',') ?>` should work.
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709480)
 * yes that works great for generating links, but I need it as a simple text… 🙂
 * Thank’s!
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709481)
 *     ```
       <?php $my_cats = get_categories(',');
       echo $my_cats;?>
       ```
   
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709482)
 * it’s just displaying the word “array” :-<
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709484)
 * My bad. Try:
 *     ```
       <?php $my_cats = get_categories();
       $num = count($my_cats);
       $c = 0;
       foreach( $my_cats as $my_cat ) {
       	$c++;
       	echo $my_cat;
       	if( $c < $num ) echo ', ';
       }?>
       ```
   
 * Warning: Off the top of my head so untested.
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709487)
 * Wow that’s a complicated one… but it’s saying:
    “catchable fatal error: object
   of class stdClass could not be converted to string” ???!!!!!???? 🙂
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709488)
 * it’s kind of weird that wordpress gives so much amazing complicated
    stuff in
   a simple code structure but some of the simplest things don’t have any short 
   code at all…
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709490)
 * I missed the closing `?>` at the end initially. Have you added that?
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709493)
 * ya sure 🙂
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709495)
 * Aha! Wrong function! Your mention of wp_list_categories threw me.
 *     ```
       <?php $my_cats = get_the_category();
       $num = count($my_cats);
       $c = 0;
       foreach( $my_cats as $my_cat ) {
       	$c++;
       	echo $my_cat->category_nicename;
       	if( $c < $num ) echo ', ';
       }?>
       ```
   
 * And I’ve tested this one. 🙂
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709502)
 * I think it works, but maybe doesn’t work well with the hebrew language…
    because
   it’s generating some “7%91%d7%a4%d7%aa%d7%97-%d7%aa%d7%a7%d7%9…” gibberish…
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709522)
 * Hmmm… that looks like an encoding problem. Try using `cat_name` instead of `category_nicename`.
 *  Thread Starter [Begin](https://wordpress.org/support/users/bentalgad/)
 * (@bentalgad)
 * [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709604)
 * Yaaaa!!! right!!!! that works great!!! Thank you very much esmi!
 * :-)))

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘get post's categories as simple text’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [get](https://wordpress.org/support/topic-tag/get/)

 * 13 replies
 * 2 participants
 * Last reply from: [Begin](https://wordpress.org/support/users/bentalgad/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/get-posts-categories-as-simple-text/#post-2709604)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
