0

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>";
}
?>
1
  • Please don't link pastebins - paste the code with proper indentation directly in the question. Thanks.
    – kaiser
    Oct 2, 2012 at 17:26

1 Answer 1

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.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .