Make WordPress Core

Opened 14 years ago

Closed 14 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's profile natecook Owned by: ryan's profile ryan
Milestone: 3.2 Priority: normal
Severity: normal Version: 3.1
Component: Comments Keywords:
Focuses: 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 14 years ago.
Patch to pass the $post_id along to get_comment_id_fields() method

Download all attachments as: .zip

Change History (4)

@natecook
14 years ago

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

#1 @natecook
14 years ago

  • Component changed from General to Comments

#2 @nacin
14 years ago

  • Milestone changed from Awaiting Review to 3.2

#3 @ryan
14 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.