0

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!

2
  • 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
    Commented Sep 17, 2012 at 23:43
  • My mistake, I want to output them because there are already registered.
    – agis
    Commented Sep 18, 2012 at 13:42

1 Answer 1

0

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.

3
  • I think I've tried to just rename the word cat but is not retrieving any tags.
    – agis
    Commented Sep 18, 2012 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
    Commented Sep 19, 2012 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
    Commented Sep 20, 2012 at 8:16

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.