[wp-trac] [WordPress Trac] #18603: Comments on pages which exceed paginate settings create erroneous permalinks

WordPress Trac wp-trac at lists.automattic.com
Wed Sep 7 16:31:57 UTC 2011


#18603: Comments on pages which exceed paginate settings create erroneous
permalinks
-------------------------+-------------------------------------------------
 Reporter:  msagman      |       Owner:  Mike Sagman
     Type:  defect       |  http://www.dogfoodadvisor.com
  (bug)                  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Comments     |     Version:  3.2.1
 Severity:  normal       |  Resolution:
 Keywords:  reporter-    |
  feedback close         |
-------------------------+-------------------------------------------------

Comment (by msagman):

 I think we've found the problem. And it does appear to be located in the
 core function of WP in the get_page_of_comment() lines. You should be able
 to reproduce the problem. As I understand it, it has to do with the logic
 of the way WP computes the page number. It appears to have something to do
 with whether the comments are approved or not. So, it only affects the
 posts containing the largest number of comments and the longest history.

 Here's a copy of what my software technician reported to me. And after
 testing his changes, the problem disappeared and was fixed:

 In /wp-includes/comment.php on line 813:
 $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID)
 FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND
 comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere,
 $comment->comment_post_ID, $comment->comment_date_gmt ) );

 In order to determine the correct page number for the most recent comment
 link you must not include approved comments and parent comments in the
 query… After changing the query above to the following I was able to
 determine the correct number of $oldercoms variable, thus affecting the
 math on line 820, by executing:

 $oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID)
 FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_date_gmt <
 '%s'" . $comtypewhere, $comment->comment_post_ID,
 $comment->comment_date_gmt ) );

 Finally, I changed the math logic to:
 return round( ( $oldercoms + 1 ) / $args['per_page'] );

 Thanks for your help.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18603#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list