0

This may be a syntax problem but if so I can't see the problem.

I want to select specific terms of a custom taxonomy and display their names. I'm having a problem with the selection process in the following code.

$taxonomy = 'chapters';
echo("Test Term Display ");
$args1=array(
    'include'=> array(74,76
        )
    );
$chaptertitles=get_terms( 'chapters', $args1 );
$count1 = count($chaptertitles);
echo($count1);
 if ( $count1 > 0 ){
   echo "<ul>";
      foreach ( $chaptertitles as $chaptertitle ) {
   echo "<li> Chapter Title:" . $chaptertitle->name . "</li>";

  }
 echo "</ul>";
}

This returns zero for $count1.

However, if I remove the arguements so that the default conditions apply then I get all the terms returned.

This suggests that my syntax is incorrect for $args1 but I can't see any errors.

I'd appreciate any suggestions on how to get this working.

Thx

  • is it possible that those terms are empty? – iEmanuele Sep 2 '13 at 9:25
  • 1
    Thx. Yes that is the problem. – dorich Sep 3 '13 at 6:09
0

This might help you to find your solution.

  1. print the result of get_terms without arguments

    $chaptertitles=get_terms( 'chapters');      
    print_r($chaptertitles);    
    
  2. Check in above result can you get the item id 74 & 76.

  3. I think you might not get the the item id 74 & 76 that's why you get the zero for $count1.

  4. Include the item which you may get in $chaptertitles.

  • Thx. As noted in my answer the solution is simply to turn off suppression of terms that don't have posts. – dorich Sep 2 '13 at 15:34
0

The solution to the problem is that by default terms having no posts are not displayed. This can be changed by adding "hide_empty"=>0 to the parameter list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.