Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type called "portfolio" with 2 registered taxonomies : portfolio_category and portfolio_tag.

I'm using a custom theme that use a lot of javascript/jquery.

So this is how the categories taxonomy is defined in template-portfolio.php (it's just some relevant code used to define categories taxonomy) :

if($pf_categorynotin){
    $args['tax_query'] = array(
        array(
            'taxonomy' => 'portfolio_category',
            'field' => 'slug',
            'terms' => $pf_categorynotin,
            'operator' => 'NOT IN'
        )
    ); //category__in
}

if( have_posts() ) : 
    while ($wp_query->have_posts()) : $wp_query->the_post();
        $post_cat = array();
        $post_cat = wp_get_object_terms($post->ID, "portfolio_category");
        $post_cats = array();
        $post_rel = ' all ';
        for($h=0;$h<count($post_cat);$h++){
            $post_rel .= $post_cat[$h]->slug.' ';
            $post_cats[] = $post_cat[$h]->name;
        }

        $attachments = get_post_meta($post->ID, '300-160-image', true);


        if ($attachments) {         
            $post_cat = array();
            $post_cat = wp_get_object_terms($post->ID, "portfolio_category");
            $post_cats = array();
            for($h=0;$h<count($post_cat);$h++){
                $post_cats[] = $post_cat[$h]->name;
            }
            $cats_pf_this = implode(", ", $post_cats);

So, this is how the categories taxonomy are defined. For define the tags taxonomy I just have to duplicate this code ? Thanks!

share|improve this question
    
Not clear exactly what you're asking. This isn't 'how the categories taxonomy are defined'. This is how the category output is generated by your template. The taxonomy registration would be somewhere else and use register_taxonomy(). –  jb510 Sep 17 '12 at 23:43
    
My mistake, I want to output them because there are already registered. –  agis Sep 18 '12 at 13:42

1 Answer 1

up vote 0 down vote accepted

If you're trying to create a output template, then yes essentially just replace the word cat or category everywhere in that code with the word tag. Something is still missing from this question though because template_portfolio.php isn't a standard template name and it's not clear how it's being called by your custom theme.

share|improve this answer
    
I think I've tried to just rename the word cat but is not retrieving any tags. –  agis Sep 18 '12 at 13:43
    
Now it seems to work, but how can I add tags also without replacing, I understand I have to duplicate them but my problem is how to define them here array( 'taxonomy' => 'portfolio_category', –  agis Sep 19 '12 at 13:44
    
You register a non-hierarchical taxonomy the same as a hierarchical one, using register_taxonomy(). Search your code for wherever register_taxonomy( shows up, duplicate that code changing portfolio_category to portfolio_tag and changing the hierarchical argument to false. read this: codex.wordpress.org/Function_Reference/register_taxonomy –  jb510 Sep 20 '12 at 8:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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