Opened 3 years ago
Last modified 7 months ago
#14195 accepted defect (bug)
$paged is not set when a Static Page is set as the Front Page
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Query | Version: | 3.0 |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
If a static page is set as the front page of your WordPress site, and you request paginated content from the page via its URL (with permalinks enabled or disabled, doesn't matter), the $paged variable is not set.
This causes custom pages (those ones displaying posts), to always go to Page 1, even if you click other pages. ( This is happening because $paged is set to null, and if it's set to null, it always goes to page 1).
Also, get_query_var('paged'), also returns null, when it should return page 2 (if you clicked on page 2 for example).
After inspecting $wp_query, I noticed that the correct paginated value is stored on
$wp_query->query['paged']
So, I have to do the following on all my themes on header.php, so the pagination doesn't break:
global $wp_query, $paged; $paged = $wp_query->query['paged'];
This sets $paged again,with the correct value from $wp_query and fixes the bug. Since $paged is null whenever a custom page is selected as your homepage.
This fix works with permalinks enabled or disabled.
Attachments (1)
Change History (11)
- Component changed from General to Query
- Keywords pagination, paged removed
To further clarify, I'm not sure if or why the 'paged' query var is set within $wp_query. A single post with paginated content uses the 'page' variable, while paginated multiple posts uses 'paged'. So $page I imagine stores exactly what you want.
If that sounds right, then the only thing that we may need to investigate is why paged is still being set deep in the query and not exposed in the query var, which doesn't sound right.
I think we should fix the root of the problem, i.e. not rely on the $paged global at all and use get_query_var() instead.
Replying to scribu:
I think we should fix the root of the problem, i.e. not rely on the $paged global at all and use get_query_var() instead.
Unless I'm missing something, the $paged global should equal get_query_var( 'paged' ), and the $page global should equal get_query_var( 'page' ). So I'm not sure that's the root of the problem.
comment:6
wonderboymusic — 7 months ago
- Milestone Future Release deleted
- Resolution set to worksforme
- Status changed from new to closed
http://wordpress-core/sample-page/page/4/ works in trunk when the page is not, in fact, paged
Query vars are present:
Array
(
[paged] => 4
[pagename] => sample-page
[error] =>
)
comment:7
wonderboymusic — 7 months ago
- Resolution worksforme deleted
- Status changed from closed to reopened
comment:8
SergeyBiryukov — 7 months ago
- Milestone set to Future Release
comment:9
wonderboymusic — 7 months ago
- Owner set to wonderboymusic
- Status changed from reopened to accepted
wonderboymusic — 7 months ago
comment:10
wonderboymusic — 7 months ago
- Keywords has-patch added
Patch attached - all Unit Tests pass when paged remains set, page remains set to the value of paged

Related/Duplicate #13840