Opened 2 years ago

Closed 2 years ago

#17193 closed defect (bug) (fixed)

comment_form() outputs ID fields related to get_the_id() even when passed a $post_id

Reported by: natecook Owned by: ryan
Priority: normal Milestone: 3.2
Component: Comments Version: 3.1
Severity: normal Keywords:
Cc:

Description

Calling comment_form() and passing in a $post_id value other than the current page's post as the second parameter results in an incorrect comment form. The form that is returned has the hidden "comment_post_ID" input field set to the ID of the current page, rather than the $post_id passed into comment_form(). This issue appears if a custom template is used to retrieve a customized group of posts (a custom content type, for example) and then display the list of posts and the associated comment forms.

// this code could be in a custom template used on a page with ID 101
// retrieve all my content from the "my_custom_type" content type, with IDs 201, 202, 203
$my_posts = get_posts("post_type=my_custom_type");

foreach ($my_posts as $my_post) {
	echo "<h3>Add a comment to post #{$my_post->ID}</h3>";
	comment_form("", $my_post->ID);
	echo "<hr />";
}

The three generated comment forms all have hidden "comment_post_ID" fields with the same value (101), when they should have values that match the headline written (201, 202, 203).

Attachments (1)

comment-template.diff (1.2 KB) - added by natecook 2 years ago.
Patch to pass the $post_id along to get_comment_id_fields() method

Download all attachments as: .zip

Change History (4)

Patch to pass the $post_id along to get_comment_id_fields() method

  • Component changed from General to Comments
  • Milestone changed from Awaiting Review to 3.2

comment:3   ryan2 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [17812]:

Pass post id along to *comment_id_fields(). Props natecook. fixes #17193

Note: See TracTickets for help on using tickets.