542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says

Hi Everyone!

I’m trying to register a new custom post type, and I want them to be organized into categories, just like posts. I read on WordPress codex that I should add a ‘taxonomies’ array, but I can’t get it working.

Here is my code:

$port1 = array(
    'label' => __('Portfolio'),
    'singular_label' => __('Portfolio'),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => true,
    'menu_icon' => get_stylesheet_directory_uri() . '/images/portfolio.png',
    'supports' => array('title', 'thumbnail', 'excerpt', 'editor', 'author', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes'),
    'taxonomies' => array('category'),
    'menu_position' => 5,
);

register_post_type( 'portfolio', $port1);

Any help is truly appreciated :)

327 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Sold between 50 000 and 100 000 dollars
  • United Kingdom
PaulWinslow says

This is what you’re looking for..

register_taxonomy("skills", array("portfolio"), array("hierarchical" => true, "label" => "Project Categories", "singular_label" => "Project Category", "rewrite" => true));

Add this after you’ve registered the post-type.

542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says
pau1winslow said
This is what you’re looking for..
register_taxonomy("skills", array("portfolio"), array("hierarchical" => true, "label" => "Project Categories", "singular_label" => "Project Category", "rewrite" => true));
Add this after you’ve registered the post-type.

Thank you! It works :)

327 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Sold between 50 000 and 100 000 dollars
  • United Kingdom
PaulWinslow says

No problem, mate :)

542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says

Hi Everyone,

Now I’ve another doubt, I have a custom post type, with categories enabled, but using the_category(); doesn’t seem to do anything. Is there any special template tag / function for calling categories of a custom post type?

I tried this code (made by ThemeProvince), but I can’t get it working:

Functions file
function the_taxonomy ($taxonomy) {

if ( empty($terms) )
$terms = wp_get_object_terms($post->ID, $taxonomy);
$terms_total = count($terms);
$terms_counter = 0;

foreach ( $terms as $term ) {
$term_output .= "$term->name";  
$terms_counter++;
($terms_counter != $terms_total) ? $term_output .= ", " : $term_output .= "";       
}

echo $term_output;

}
Portfolio Page
$port1= array( 'post_type' => 'portfolio' ); // Query definitions

query_posts( $port1 ); // Get Portfolio Items
    while ( have_posts() ) : the_post(); // Here starts the Portfolio Area

            echo '<div class="box_cat">';
                the_taxonomy('skills'); 
            echo '</div>';

    endwhile;// Here Ends the Portfolio Area
wp_reset_query(); //Reset the Query

Am I missing something?

542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says

Hi,

Got it working using this code:

echo get_the_term_list( $post->ID, 'skills');

:)

2566 posts Put a Donk On It
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Exclusive Author
  • Attended a Community Meetup
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 200 and 499 users
+5 more
ThemeProvince says

My code works if you make $post global. I’ve used it in all my themes.

542 posts
  • Exclusive Author
  • Europe
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Blog Post
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
ThemesFever says
ThemeProvince said
My code works if you make $post global. I’ve used it in all my themes.

Next time I will use it :) Thank you!

271 posts
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
Anjum says
ThemeProvince said
My code works if you make $post global. I’ve used it in all my themes.

+1

global $post is necessary

1525 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 3-4 years
webdesignerart says
diogoredin said
pau1winslow said
This is what you’re looking for..
register_taxonomy("skills", array("portfolio"), array("hierarchical" => true, "label" => "Project Categories", "singular_label" => "Project Category", "rewrite" => true));
Add this after you’ve registered the post-type.
Thank you! It works :)

+1 yes this i also try in my custom post type category it works :)

by
by
by
by
by
by