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 have a small isuue, this code retrive me the parent categories from a post type.

The post_type is : serial The taxonomy is : seriale

<?php 
$terms = get_terms('seriale','child_of=668');foreach ($terms as $term) {echo '<a href="'.get_term_link($term).'">'.$term->name.'</a>';}
?>

The problem is: after i added another post in my site it my theme it aprear on all duplicate.

EX: First post - i select Year 2011 Second post - i select Year 2012

In archive it retrive me for the first and second post...

:2011,2012 ...

I want to be able to get only wath i select... I want to get categories only for child_of=668

Wath im doing rong. Thanks

share|improve this question

1 Answer 1

get_terms retrieves all terms in a taxonomy, not terms added to a post.

you want to use get_the_terms to retrieve terms assigned to a specific post. there are no additional arguments to filter the list of terms returned, you'll have to manually check a term's parent to only output terms that are a child of a specific term id.

$terms = get_the_terms( $post->ID, 'seriale' );
foreach( $terms as $term ):
    if( 668 == $term->parent ){
        echo $term->name;
    }
endforeach;
share|improve this answer
    
thanks it works –  Batman Feb 4 '13 at 0:59

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.