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'm working with a hierarchical taxonomy (named "world") that has 3 levels to it (Regions > Countries > Indigenous Peoples). At the moment I'm using a modified version of this code to paginate all the results on a single page.

Here's the important part

$page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
// number of tags to show per-page
$per_page = 24;
$offset = ( $page-1 ) * $per_page;
$args = array( 'number' => $per_page, 'offset' => $offset, 'hide_empty' => 1,'hierarchical ' => true
);

and

$taxonomy = 'world';
$tax_terms = get_terms( $taxonomy, $args );

As expected, this returns a paginated list of all the terms associated with my taxonomy. The problem is, I only actually need to show the grandchildren, in this case, "Indigenous Peoples".

I'm tempted do it manually, but I'd rather not serve up a list of 450+ terms to include (or 80 terms to exclude) unless it's absolutely necessary.

Your help would be most appreciated.

share|improve this question
add comment

2 Answers

Have you tried looking at this post, Get child taxonomy in <ul>? It might be helpful, it seems like once you get the child taxonomy you can use that for your search query?

share|improve this answer
    
Thanks @Donna. I might use that code for another project, but I'm really not sure how I would go about using it to get the grandchildren. That's the problem I'm having: how can I actually display those terms (or alternatively, exclude just the parent and child terms)? I've found lots of great solutions for getting child terms, but there doesn't seems to be anything for grandchildren. –  John Schertow Jul 11 '12 at 15:00
add comment

I think for each term you should check that it has a parent but not have any childern

So you code may look like

    $taxonomy = 'world';
    $tax_terms = get_terms( $taxonomy );
    foreach ($tax_terms as $value){
        $args=array(
            'child_of'=> $value->term_id,
            );
        //get all child of current term
        $child = get_terms( $taxonomy, $args );
        if( $value->parent != '0' && count($child) =='0'){
            echo $value->slug;
            echo '<br/>';
            //do something because it's your lowest level term which have parent but not have any childern
        }
    }
share|improve this answer
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.