-3

I have a custom post type. In that post type the taxonomy is category and I have to display the all the categories of the custom post type i.e. project.

I want to like option list.

My custom post type is "Project".

3

1 Answer 1

0

In actual custom post types are same as normal posts in WordPress. The only difference is there isn't any in-built WordPress functions to get the information you need, but you can get it by using the wp_query class. This offers a nice way to access all the information in your WordPress database.

To get the custom post type categories you need to change the arguments passed into the wp_list_categories function.

You need to define the taxonomy argument.

If you have a custom post type for your products then to display all the categories for products you need to use the following snippet.

$customPostTaxonomies = get_object_taxonomies('products');

if(count($customPostTaxonomies) > 0)
{
 foreach($customPostTaxonomies as $tax)
 {
     $args = array(
          'orderby' => 'name',
          'show_count' => 0,
          'pad_counts' => 0,
          'hierarchical' => 1,
          'taxonomy' => $tax,
          'title_li' => ''
        );

     wp_list_categories( $args );
 }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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