WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#13471 closed defect (bug) (fixed)

Pagination in Blog Post Won't Display Past Page 1

Reported by: krowland08 Owned by: nacin
Milestone: 3.0.2 Priority: normal
Severity: critical Version: 3.0
Component: Canonical Keywords: has-patch
Focuses: Cc:

Description

I've posted a multi-page post a few days ago, and that post is paging, but the last couple days, every multi page post will revert to showing only page one.

Both posts use the <!--nextpage--> tag in source. Both posts show the pages numbers at the bottom of page 1. Both posts have the correct link URL, ....postname/2/ ..postname/3/ etc.

However when clicking on any of the pages, only the first page is returned. This only effects recently entered new posts, as a previous post from a few days ago, still pages fine.

I will attempt to repost the OLD content in a new post and try to find the difference and return my findings.

Attachments (2)

13471.diff (966 bytes) - added by blepoxp 6 years ago.
Checks for multiple categories and only submits last category to get_term_by
13471.2.diff (875 bytes) - added by nacin 6 years ago.
Original patch from glenn.

Download all attachments as: .zip

Change History (21)

#1 @krowland08
6 years ago

  • Cc krowland08 added

Ok, here is the scoop. If the post is in a nested category, the pagination fails. If the the post is in a top level category the post paging will work. It's like the URL will only take 2 segments, category and post title.

Now this all is because I am setting my permalinks to /%category%/%postname%/

And this works for generating multi level categories. However if there is a nested category, then the PAGE number gets lopped off.

And sure enough, if I resort to one of the default permalink setting, the pagination works.

So what is wrong with using: %category%/%postname%/ with pagination?

#2 @krowland08
6 years ago

Work-Around

I've resorted to using just %postname%/ in my custom permalink settings and since there is only one argument before the page number. sitename.com/page-title-here/##/ this works.

#3 @Usurper
6 years ago

  • Keywords permalink added

Thank you for posting the workaround. I've been going nuts. I'm amazed this isn't a more prevalent problem.

#4 @Killing
6 years ago

Yes been chasing this today :(

The cause is the fix applied in r13781 of wp-includes/canonical.php which added the following code to fix #11807

} elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) {
           $category = get_term_by('slug', get_query_var('category_name'), 'category');
           $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids'));
           if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) )
               $redirect_url = get_permalink($wp_query->get_queried_object_id());

The problem is that get_term_by doesn't support hierarchies so when passed a second level category e.g. cars/sports it will fail and hence the rewrite is performed loosing the page information.

The following fixes this but I'm not 100% that the intention is to only check the last category in the hierarchy, although with our data anything more would appear to fail. This may indicate that additional fixes are required but anyway:-

$category = get_term_by('slug', end( explode( '/', get_query_var('category_name') ) ), 'category') ;

#5 @Killing
6 years ago

  • Cc Killing added
  • Severity changed from normal to critical

#6 @Killing
6 years ago

Increased severity as this causes major site breakage for those that use this permalink structure.

#7 @Killing
6 years ago

Ooo nasty bug to still leave unresolved in 3.0.1 :(

#8 @nacin
6 years ago

  • Keywords needs-patch added; pagination nextpage permalink removed
  • Milestone changed from Awaiting Review to 3.0.2

#9 @techlover
6 years ago

  • Cc jamie@… added

@blepoxp
6 years ago

Checks for multiple categories and only submits last category to get_term_by

#10 @blepoxp
6 years ago

  • Keywords has-patch needs-feedback added; needs-patch removed

Patch worked on r15483 (3.0.1).

#11 @blepoxp
6 years ago

  • Keywords needs-testing added; needs-feedback removed

#12 @designsimply
6 years ago

Patch worked on r15497

#13 @nacin
6 years ago

  • Keywords commit added; needs-testing removed

#14 @nacin
6 years ago

  • Keywords commit removed
  • Owner set to nacin
  • Status changed from new to reviewing

Actually, no need for the conditional. explode() will always return an array, with a size of one if there's no child categories.

Also, end(explode()) triggers an E_STRICT here, which means it likely throws a fatal on PHP 5.0.5 and 4.4 (#14160). Solution is to do it in two steps, or awkwardly assign a variable inside, like end( $foo = explode(...) ).

Patch attached, untested, should have proper logic.

@nacin
6 years ago

Original patch from glenn.

#15 @nacin
6 years ago

Actually... we should probably be using get_category_by_path().

#16 @nacin
6 years ago

As an additional enhancement to this: It should actually confirm that category_name is equal to the proper path. Otherwise, /fake-category/real-category/ will not redirect to /real-parent/real-category/.

#17 @dd32
6 years ago

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

(In [15707]) Fix canonical redirection for permalinks containing %category% with nested categories and paging. Fixes #13471 for trunk

#18 @dd32
6 years ago

(In [15708]) Fix canonical redirection for permalinks containing %category% with nested categories and paging. Fixes #13471 for 3.0 branch

#19 @dd32
6 years ago

  • Component changed from Formatting to Canonical
Note: See TracTickets for help on using tickets.