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: |
|
Owned by: |
|
|---|---|---|---|
| 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).

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