1

I have this simple snippet to retrieve the categories (taxonomies) of my Custom Post Type 'portfolio' I need to display each taxonomy but it displays all the categories.

I just saw this question Filter get_categories() for taxonomy term in WordPress and unfortunately I tried with no success.

<?php
    query_posts("post_type=portfolio");
    if ( have_posts() ) : while ( have_posts() ) : the_post(); 
    $catid = get_cat_id('Images');
?>

<?php 
    $categories=  get_categories('child_of='.$catid.'&orderby=name'); 
    foreach ($categories as $cat) {
    $input = '<li><a href="#" data-value="category-'.$cat->category_nicename.'">';
      $input .= $cat->cat_name;
      $input .= '</a></li>';
      echo $input;
      }
?>

Can you please guide me or give me a hint? Thanks so much.

  • categories (taxonomies) Category is taxonomy but other taxonomies are not categories. Could you please explain better what exactly you want to retrieve? Terms from several taxonomies? – Rarst Jan 13 '11 at 8:30
  • Can you give us an idea of what type of data/use-case you are working with? Like @Rarst I don't understand what you are trying to accomplish. – MikeSchinkel Jan 13 '11 at 8:33
  • Sure let me explain better. I have a Custom Post Type in my custom post type I've created a Custom Taxonomy called 'Portfolio' with 1 category called 'Work' (parent) with 3 childs (Images, Video Production, Web Design). I want to display the Name of the child categories into a list. Sorry for my english – Ivor Jan 13 '11 at 8:44
0

First, you are mixing up terminology a bit. Portfolio is taxonomy, but Work, Images, etc are terms (not categories).

So you need to adjust functions for your taxonomy. Try this:

Replace:

$catid = get_cat_id('Images');

Becomes:

$catid = get_term_by( 'name', 'Images', 'portfolio' );
$catid = $catid->term_id;

And:

$categories = get_categories('child_of='.$catid.'&orderby=name'); 

Becomes:

$categories = get_categories('child_of='.$catid.'&orderby=name&taxonomy=portfolio');

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.