Search code examples
wordpresscustom-post-type

get_categories for Custom Post Type


I have a Custom Post Type, 'ioni_codex' I am using built-in Wordpress category as taxonomy

I want to list all categories used by 'ioni_codex'.

I assume that this code will do the trick:

$myargs = array (
    'type' => 'ioni_codex'
); 
$categories = get_categories( $myargs );

However instead I see the list of all categories not the categories assigned to by 'ioni_codex'.

What Am I doing wrong?


Solution

  • get_categories() does not accept post_type as an argument, use taxonomy instead and refer to the taxonomy by the name you gave it when registering it. Here is a link to the codex which can explain it in more detail - http://codex.wordpress.org/Function_Reference/get_categories.