[wp-trac] [WordPress Trac] #23134: Pagination not working in custom post type homepage when there are no posts
WordPress Trac
noreply at wordpress.org
Mon Jan 7 13:07:45 UTC 2013
#23134: Pagination not working in custom post type homepage when there are no posts
--------------------------+------------------------
Reporter: kcssm | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Query | Version: 3.5
Severity: normal | Resolution: duplicate
Keywords: |
--------------------------+------------------------
Comment (by mdgl):
Yes, to clarify, you can't do this sort of thing in the template
(index.php)!
The problem is that the determination of whether a 404 "page not found"
should be returned is done before your code is ever executed.
Instead, the current page index is checked against the main query (for
"posts") and if out of range, a 404 is generated. In your case, you have
no posts, so this will be true for everything except the first page.
When your template is loaded, you perform a new query and this will
correctly setup links to the various pages for your custom post type
"gallery". The problem is that those links, once selected are checked for
a 404 against the main query as described above and before your code has
had a chance to execute.
Does that make sense? Modifying the main query using the `pre_get_posts`
hook can be tricky but is really the only correct way of achieving what
you want.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23134#comment:14>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list