I cannot get the comments_popup_link to display with the posts retrieved by the foreach loop. Only the title and permalink are displayed. Any idea why the comment link is left out?

    echo '<div id="tab-news" class="tab-all"><a id="link-news" class="link-all" href="/news">News</a></div><ul>';
    foreach($ids as $id){
       echo '<li><a href="'.get_permalink( $id ).'">'.get_the_title( $id ).'</a>';
       if ( comments_open() ) :
       echo '<p>';
       comments_popup_link( '', '<span class="onecomment">1 comment</span>', '<span class="morecomments">% comments</span>', '');
       echo '</p>';
    echo '</li></ul>';
  • well, it might be stupidly trivial for me to ask, but do you have comments open on the global site configuration ? or maybe disabled on specific posts ?
    – krembo99
    Feb 27, 2012 at 3:29

1 Answer 1


the comments_popup_link() function will only work when used within the_loop; a 'foreach' loop using post Ids is not the same.

you could try to build your own link, based on this function: get_comments_number( $id ).

  • 1
    Thank you! Realized it as well and gave up on the idea and used the normal wordpress loop. The advantage of the foreach loop is that it lets me separate logic and presentation.
    – sarytash
    Feb 27, 2012 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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