I want to create a page where visitors can give a reference (ID) of a post and when they click on submit they get an overview of all given comments on that particular post.

I think I have to create a function behinde the submit button?

Thanks for helping me out. I'm farely new to Wordpress.

KR, Kim

  • Why the user input? Who would know the post-ID?
    – matjaeck
    May 25 '16 at 15:09
  • 1
    Jekyll OP might have a drop-down of posts with titles and post-ID as option values..
    – Ismail
    May 25 '16 at 15:49

You should use get_comments( $args ) and add the post ID in the arguments ($args) array:

$post_id = 1; // post ID here from the submitted data
$comments = get_comments(array( 'post_id' => (int) $post_id ));
// dump the comments found
print_r( $comments );

That would get you a comments list on that post. Hope that helps.

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