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 the following code to list all terms, but I need a code where I can list only "parent terms" as they all have child terms too

<?php
// output quick links list of countries
$terms = get_terms('apptypes');
if (count($terms)) {
echo "<h3>Quick links</h3>";
echo "<p style=\"text-align:center;\">";
}
$i=0; // counter for printing separator bars
foreach ($terms as $term) {
$wpq = array ('taxonomy'=>'apptypes','term'=>$term->slug);
$query = new WP_Query ($wpq);
$article_count = $query->post_count;
echo "<a href=\"#".$term->slug."\">".$term->name."</a>";
// output separator bar if not last item in list
if ( $i < count($terms)-1 ) {
echo " | " ;
}
$i++;
}
if (count($terms)) {
echo "</p>";
}
?>
share|improve this question
    
Please don't link pastebins - paste the code with proper indentation directly in the question. Thanks. –  kaiser Oct 2 '12 at 17:26

1 Answer 1

get_terms('apptypes','orderby=id&parent=0');

parent argument is used to get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.

See Codex.

share|improve this answer

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.