Ticket #13471 (closed defect (bug): fixed)

Opened 21 months ago

Last modified 16 months ago

Pagination in Blog Post Won't Display Past Page 1

Reported by: krowland08 Owned by: nacin
Priority: normal Milestone: 3.0.2
Component: Canonical Version: 3.0
Severity: critical Keywords: has-patch
Cc: krowland08, Killing, jamie@…

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

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

Change History

  • 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?

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.

  • Keywords nextpage, permalink added; nextpage removed

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

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') ;
  • Cc Killing added
  • Severity changed from normal to critical

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

Ooo nasty bug to still leave unresolved in 3.0.1 :(

  • Keywords needs-patch added; pagination, nextpage, permalink removed
  • Milestone changed from Awaiting Review to 3.0.2
  • Cc jamie@… added

Checks for multiple categories and only submits last category to get_term_by

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

Patch worked on r15483 (3.0.1).

  • Keywords needs-testing added; needs-feedback removed

Patch worked on r15497

  • Keywords commit added; needs-testing removed
  • 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.

nacin18 months ago

Original patch from glenn.

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

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/.

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

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

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

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