WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

// 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 " | " ;
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

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


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.