Get WordPress comments outside of WordPress

Tagged WordPress

Sometimes you want to access WordPress content outside of WordPress. There are various pages that explain how to this and it’s really easy to do as well. What I tried to do was a little different though, I wanted to print comments outside of WordPress.

To my surprise wp_list_comments() didn’t output anything inside my custom loop. It turned out that $wp_query->comments was NULL, which I think is rather odd. I would have expected it to be defined like in a normal loop inside WordPress. However, the fix is trivial:

 $post->ID,
        'status' => 'approve',
        'order' => 'ASC'
    );
    $wp_query->comments = get_comments( $args );
    wp_list_comments( );
    comment_form();
}

comment_form() is a WordPress 3.0 feature by the way, so you may not want to use it yet.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. Nesting WordPress loops
  2. Move WordPress Comments
  3. Moving WordPress comments
Leave a Reply

Your email is never shared. Required fields are marked *

*
*