Question

Basically I've created a custom post type in WordPress with a custom taxonomy (custom_tax). Now I've created a custom query in which I'd like to grab the custom category in which the custom post was saved and output its name as a string. I was doing this while working with WordPress standard taxonomy:

//Start the query
   query_posts(array(
  'showposts' => $posts,
  'orderby' => 'asc',
  'category_name' => $category
));

$temp_title = get_the_title();
$temp_link = get_permalink();
$temp_excerpt = get_the_excerpt();
$temp_time = get_the_date('Y-m-d');
$temp_categories = get_the_category(', ');
$temp_author = get_the_author();
$temp_content = get_the_content();
$i++;

$output2 .= "<li class='item' data-id='id-" . $i . "' data-type='" . $temp_categories . "'><a href='" . $temp_link . "' rel='prettyPhoto[portfolio]'><img class='' src='" . $path . "/library/timthumb.php?src=" . $image[0] . "&h=130&w=210&zc=1&q=100' alt='" . $temp_title . "' /></a></li>";

and it worked like a charm. Now I need to use custom post and custom taxonomy and have tried many variations of this:

//Start the query
query_posts(array(
  'post_type' => array('post', 'portfolio'),
  'showposts' => $posts,
  'orderby' => 'asc',
  'category_name' => $category
));

$temp_title = get_the_title();
$temp_link = get_permalink();
$temp_excerpt = get_the_excerpt();
$temp_time = get_the_date('Y-m-d');
$temp_categories = get_the_terms( get_the_ID(), 'custom_cat', ', ' );
$temp_author = get_the_author();
$temp_content = get_the_content();
$i++;

$output2 .= "<li class='item' data-id='id-" . $i . "' data-type='" . $temp_categories . "'><a href='" . $temp_link . "' rel='prettyPhoto[portfolio]'><img class='' src='" . $path . "/library/timthumb.php?src=" . $image[0] . "&h=130&w=210&zc=1&q=100' alt='" . $temp_title . "' /></a></li>";

And it doesn't work. I've tried get_the_terms(), the_terms() and get_terms() but none worked like get_the_category() worked before - it was outputting a string with the category name. Wha am I missing?

Many thanks

Was it helpful?

Solution

Wordpress describes taxonomies as "Terms". There may be some help in their documentation on "get_terms()" found here. If you want to sort by terms there is a great post on the wordpress forums to do just that!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top