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 was hoping somebody could help me out with custom fields.

I created a custom post type called game-type in WordPress. In this I have the categories "Android", "iOS" and "PC", then within these I have categories for types of games "3D Action", "Classics", "Platform" etc.

So an example hierarchy for each post works like this: Games > Android > 3D Action > Post (Game)

So far I've managed to call a list of categories using the code:

`

$taxonomy     = 'game-type';
$orderby      = 'name';
$show_count   = 0;      // 1 for yes, 0 for no
$pad_counts   = 0;      // 1 for yes, 0 for no
$hierarchical = 1;      // 1 for yes, 0 for no
$title        = '';

$args = array(
 'taxonomy'     => $taxonomy,
 'orderby'      => $orderby,
 'show_count'   => $show_count,
 'pad_counts'   => $pad_counts,
 'hierarchical' => $hierarchical,
 'title_li'     => $title
);
?>

<ul>
<?php wp_list_categories( $args ); ?>
</ul>`

But this lists all the categories in my custom field. Is there a way to target just the categories in "android"?

Your help would be much appreciated.

Thanks

Site: http://www.sugartree.org.uk/company

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Have you tried using include/exclude?

$taxonomy     = 'game-type';...
$include      = 'ANDROID ID IE: 1'

    $args = array(...
        include           => $include
    );

EDIT: vancoder is right: it should be...

   $taxonomy     = 'game-type';...
    $child_of= 'ANDROID ID IE: 1'

        $args = array(...
            child_of    => $child_of
    );

Where $child_of is the ID of your subcategory.

share|improve this answer
    
Brandon = the include seems to be getting somewhere but it's cutting out the child categories and just leaving a link to Android. I may have written it wrong, I've put: $include = '4&post_type=games';... 'include' => $include, –  user27833 Feb 21 '13 at 21:25
    
@user27833 user ` for code or edit original question. You also may need a mixture of mine and vancoder's solution. (PS. it's Bandon) –  BandonRandon Feb 21 '13 at 21:27
    
I've tried $child_of = '4&post_type=games'; and $child_of = 'ANDROID ID IE: 1'; They both deliver 'No categories' am I writing the ID wrong? –  user27833 Feb 21 '13 at 21:47
    
Maybe, It should be the ID of the Android category. It looks like you have missing quotes. meaning it should be child_of = 4&taxonomy=game-type post_type is not allowed as an accepted argument of wp_list_categories –  BandonRandon Feb 21 '13 at 21:52
    
That's still delivering 'no categories' the full ID from looking at categories (which is how i'd usually find the ID is : /edit-tags.php?action=edit&taxonomy=game-type&tag_ID=4&post_type=games –  user27833 Feb 21 '13 at 22:11
show 6 more comments

Add

child_of => [id for android]

to your args.

share|improve this answer
    
Would I write it like this? 'child_of' => [4&post_type=games], It's not sending me anything back. –  user27833 Feb 21 '13 at 21:31
1  
Please see example below. –  vancoder Feb 21 '13 at 21:43
    
I solved it. I just need the number from the ID, that's it: $child_of = '4' –  user27833 Feb 25 '13 at 16:04
add comment

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.