WordPress.org

Ready to get started?Download WordPress

Forums

are_trackbacks() (1 post)

  1. ikiru
    Member
    Posted 6 years ago #

    For a theme I'm working on, I want a simple way to tell if a given post -- the current one -- has trackbacks (and/or pingbacks). I thought this would be rather simple (or even built into WordPress) but it doesn't seem to be.

    If you have a good idea for how to do this, please share it. If not, I'd appreciate any feedback on this PHP function.

    function are_trackbacks($comments) {
      foreach ($comments as $comment) {
        if (get_comment_type() != 'comment') {
          return true;
        }
      }
      return false;
    }

    I'm pretty sure this is failing because of something I don't understand about foreach loops, arrays, or return. But my thinking was that I could just cycle through the "comments" on a post until I found a trackback or pingback (i.e. not having the comment type comment), which would cease the loop and make the function return true. If the loop went through all the comments and found only comments (i.e. only comment type comment), it would return false. It seemed straight-forward but pretty clearly isn't working for me.

    Any help at all is appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic