DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
564 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment 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 :)

330 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
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.

DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
564 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment 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 :)

330 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
PaulWinslow says

No problem, mate :)

DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
564 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment 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?

DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
564 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment says

Hi,

Got it working using this code:

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

:)

2580 posts Put a Donk On It
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+10 more
ThemeProvince says

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

DiogoRedinDevelopment
DiogoRedinDevelopment Recent Posts Threads Started
564 posts
  • Located in Portugal
  • Contributed a blog post
  • Helped several times protecting Envato Market against copyright violations
  • Has sold $5,000+ on Envato Market
+4 more
DiogoRedinDevelopment 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!

274 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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

1578 posts
  • Has been part of the Envato Community for over 3 years
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
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