WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#5439 closed defect (bug) (worksforme)

page displaying wrong comments

Reported by: dcostalis Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.3.1
Component: Template Keywords: comments has-patch widgets 2nd-opinion
Focuses: Cc:

Description

Depending on how widgets are set up, and the layout of the page, WordPress may display the wrong comments for a post.

The widget.php file uses a variable $id, which is used frequently throughout code. That variable is not unset, and moving the sidebar code above the comment code while this widget is active will cause the comments_template function to instead display comments from the last post on the "recent posts" list. solution proposed.

Attachments (5)

widgets.php[1].diff (310 bytes) - added by dcostalis 7 years ago.
updated proposed fix
fix_comments_query.patch (388 bytes) - added by ionfish 7 years ago.
reset_query.diff (831 bytes) - added by ryan 7 years ago.
reset_query.2.diff (851 bytes) - added by ryan 7 years ago.
recent_query_3.diff (433 bytes) - added by ionfish 7 years ago.

Download all attachments as: .zip

Change History (18)

@dcostalis7 years ago

updated proposed fix

comment:1 @ionfish7 years ago

Tarski hacks around this issue by adding the following code below the sidebar widgets block, but it would be much better if this weren't necessary.

$wp_the_query->current_post--;
setup_postdata($wp_query->next_post());

comment:2 @ionfish7 years ago

  • Keywords needs-patch added

Patch from 12/07/07 doesn't work for me. Included post reset does fix it, but obviously ideally the widgets code would be better isolated from the page or post loop.

comment:3 @ionfish7 years ago

  • Component changed from General to Template
  • Keywords has-patch widgets 2nd-opinion added; needs-patch removed

Added a patch that seems to fix this.

@ryan7 years ago

comment:4 @ryan7 years ago

How about having wp_reset_query() reset the global post data? See patch (untested).

comment:5 @ryan7 years ago

Does that patch work for anyone?

comment:6 @ionfish7 years ago

Sorry, been a really busy week. Having just tested this, it doesn't seem to fix my Tarski issue. I commented out the hack I mentioned above, applied the hack, and found all my posts getting the same comments, from the last article on the 'Recent Articles' widget list.

@ryan7 years ago

comment:7 @ryan7 years ago

Maybe that will work better.

@ionfish7 years ago

comment:8 @ionfish7 years ago

Doesn't work... but this does.

comment:9 @ryan7 years ago

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

(In [6653]) Restore global post when resetting the query. Props ionfish. fixes #5439

comment:10 @ryan7 years ago

(In [6688]) Don't advance post counter when resetting query. see #5439

comment:11 @ryan7 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Using next_post() causes problems with other themes. Reverting and reopening.

comment:12 @ionfish7 years ago

  • Milestone 2.5 deleted
  • Resolution set to worksforme
  • Status changed from reopened to closed

#6687 has resolved this for me.

Note: See TracTickets for help on using tickets.