This is a part from the code that is used to display portfolio categories:

$post_cat = array();
                    $post_cat = wp_get_object_terms($post->ID, "portfolio_category");
                    $post_cats = array();

         $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();

                        $cats_pf_this = implode(":", $post_cats);

        $fg_imagemain.='{"url": "'.get_bloginfo('template_directory').'/image.php?'.str_replace("&", "&", $image_resizer_output).'image='.$attachments.'", "aid": '.$post->ID.', "color": "'.addslashes(get_post_meta($post->ID, 'thumbnail_hover_color', true)).'", "thumb_title": "'.addslashes($thumb_title).'", "thumb_descr": "'.addslashes($thumb_descr).'", "thumb_cats": "'.addslashes($cats_pf_this).'", "fullimgsrc": "}';

        var fg_divhoverbgmetadata = $("<div>").addClass("hoverbgpfthnailmetadata").html('<span class="thumb_title">'+srcobj.thumb_title+'</span><span class="thumb_cats">'+srcobj.thumb_cats+'</span><span class="thumb_plus">+</span>');

What I want to do, is, to display also the portfolio tags. I think the first step is to duplicate this:

$post_cats = array();
                    $post_cat = wp_get_object_terms($post->ID, "portfolio_category");

like :

$post_tags = array();
                    $post_cat = wp_get_object_terms($post->ID, "portfolio_tags");

and the same for rest of the code. I've tried this but with no success, I can't make it work to display portfolio items tags. What am I doing wrong?

  • Nobody? My question is not relevant?
    – agis
    Sep 3 '12 at 13:00

You will need to know the name for your "portfolio_tags" taxonomy. Check where it is defined as a custom taxonomy, and it will need to be added to the portfolio custom post type.

The register_taxonomy() function would be your theme like this:

   array('hierarchical' => false, 'show_ui' => true, 'query_var' => true, 
   'rewrite' => array( 'slug' => 'portfolio-tags' )));

Or you could be using a custom post / custom taxonomy plugin -- then you would need to check what id was given (for example, it could be "portfolio_tag" instead)

Once you have confirmed this, you should use get_the_terms() instead, since it is part of the Wordpress API (wp_get_object_terms() isn't using the object cache so it would be less efficient)

 $post_cat = get_the_terms( $post->ID, 'portfolio_tags' );

Finally, in order to use $post-ID, make sure you are in The Loop or you have referenced the global $post object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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