this code below lists wordpress categories and works

<form action="<?php bloginfo('url'); ?>/" method="get">
$select = wp_dropdown_categories('show_option_none=Select Category&show_count=1&orderby=name&echo=0&selected=6');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
<noscript><input type="submit" value="View" /></noscript>

But I have a custom post type called portfolio and I want to list all categories of portfolio in the same way can anyone help?

  • 1
    This should be fairly easy. On the function wp_dropdown_categories(), you just have to add another parameter taxonomy. like - wp_dropdown_categories('taxonomy=portfolio_cat'). You have to figure out the name of portfolio category taxonomy and replace with portfolio_cat. – Shazzad Oct 14 '14 at 14:23
  • thankyou for your response but unfortunatly it doesn list any category I just tried like this : wp_dropdown_categories('taxonomy=portfolio&show_option_none=Select Category&show_count=1&orderby=name&echo=0&selected=6'); – Jessy Oct 14 '14 at 14:28
  • If your Custom post type name is "portfolio", the same won't be for the taxonomy name. You just have to figure-out the name. Visit the WP Admin Portfolio Categories page, and look at the url where it says &taxonomy=. – Shazzad Oct 14 '14 at 14:30
  • I used this tutorial here jasonskinner.me/2013/03/… – Jessy Oct 14 '14 at 14:33

Use the following function: wp_list_categories();. You can find more information on the codex.

Here is how to display the list:

<?php $args = array(
    'taxonomy'    => 'portfolio_taxonomy', // your custom post type Taxonomy
    'order'       => 'ASC' // Order of the list

wp_list_categories($args); ?>
  • Thanks but now its not visible more so maybe something missed in functions.php? – Jessy Oct 14 '14 at 14:37
  • <?php $args = array( 'taxonomy' => 'portfolio', // your custom post type Taxonomy 'order' => 'ASC' // Order of the list ); $select = wp_list_categories($args); $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); echo $select; ?> – Jessy Oct 14 '14 at 14:38
  • I'm not sure what you are trying to achieve with the whole piece of code but if you want to display a list of your CPT taxonomy just use the code above. You need to have a custom taxonomy registered for this Custom Post Type though using register_taxonomy(); function (in your functions.php). Here is more information about this function. – Pipo Oct 14 '14 at 14:43
  • Yes register_taxonomy() is ok but I dont know why it doesnt list anything I have posts in portfolio and a portfolio page I just want to list the categories of portfolio as design,broscures etc. – Jessy Oct 14 '14 at 14:45
  • What's the name of your portfolio taxonomy? You need to put the taxonomy name in the 'taxonomy' => argument instead of custom post type name. – Pipo Oct 14 '14 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.