#25246 closed defect (bug) (wontfix)
Make WP_Query (pagination) to load after template is loaded
Reported by: | alexvorn2 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.6 |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
The problem is that the pagination is calculated before the template is loaded, so sometimes the page/2
does not contain the posts requested or does not display the posts at all.
On other hand this will help to load multiple posts types on the main query with not breaking the pagination, adjust number of posts per page depending on custom posts type or main post type - on different archive pages:
Ex: on category.php page to display only 5 posts at most but on index.php - 20 posts at most.
Of course we can use some custom actions that will change the value of the pre_get_posts
but my ticket is for modification of the WP_Query itself so the pagination will be calculated like on Page Templates does.
Change History (8)
#2
in reply to:
↑ 1
@
11 years ago
Replying to markoheijnen:
I'm not sure what you are requesting.
pre_get_posts
seems to be the proper filter for this things.
As I mentioned in the ticket is that we can use the filter pre_get_posts
to modify the value but I this seems not the good thing when we have a custom property in the arguments of a custom query, example:
The Query
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' => 3, 'paged' => $paged ); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<p>' . get_the_title() . '</p>'; } }
So if we have only 4 posts and we want to use the posts_per_page property to show 3 posts it works, but we will go to page/2 to show the last 1 post, it will show as a 404 error page instead.
So that's why I opened this ticket, I request this.
#3
follow-up:
↓ 4
@
11 years ago
- Keywords close added
If you're doing a new WP_Query()
within the page then that query is unrelated to the URL of the page you're on. The two are not and should not be connected. The 404 you get from your example is generated by the main query, which is separate from your secondary query.
The pre_get_posts
filter is what you need here.
Suggesting close as invalid.
#4
in reply to:
↑ 3
@
11 years ago
- Keywords close removed
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
#6
in reply to:
↑ 5
@
11 years ago
Replying to alexvorn2:
Ok, but I'm sure 100% this will get attention again later :)
I doubt that unless you provide a better example or a patch. In this case just use pre_get_posts
and don't touch pages at all. Nothing can go wrong then unless you want pagination on the custom query you have in your theme. That is almost unfixable.
I'm not sure what you are requesting.
pre_get_posts
seems to be the proper filter for this things.