Pagination issue with query variable type

Hi,
Just playing around with pagination and have an issue:

Paginating a loop to 40 per page works fine for the first page. The second and the following pages returns this:

{"original_post":null,"args":{"type":"circuit","oderby":"title","order":"asc","paged":"40","instance":"true","paginator":"true","page":"4"},"index":-1,"query":{"query":{"post_type":["circuit"],"post_status":["publish"],"ignore_sticky_posts":true,"orderby":"title","order":"ASC","posts_per_page":-1,"paged":1,"fields":"ids","post_parent":0},"query_vars":{"post_type":["circuit"],"post_status":["publish"],"ignore_sticky_posts":true,"orderby":"title","order":"ASC","posts_per_page":-1,"paged":1,"fields":"ids","post_parent":0,"error":"","m":"","p":0,"subpost":"","subpost_id":"","attachment":"","attachment_id":0,"name":"","pagename":"","page_id":0,"second":"","minute":"","hour":"","day":0,"monthnum":0,"year":0,"w":0,"category_name":"","tag":"","cat":"","tag_id":"","author":"","author_name":"","feed":"","tb":"","meta_key":"","meta_value":"","preview":"","s":"","sentence":"","title":"","menu_order":"","embed":"","category__in":[],"category__not_in":[],"category__and":[],"post__in":[],"post__not_in":[],"post_name__in":[],"tag__in":[],"tag__not_in":[],"tag__and":[],"tag_slug__in":[],"tag_slug__and":[],"post_parent__in":[],"post_parent__not_in":[],"author__in":[],"author__not_in":[],"search_columns":[],"tax_query":[{"taxonomy":"language","field":"term_taxonomy_id","terms":[2],"operator":"IN"}],"update_post_term_cache":true,"suppress_filters":false,"cache_results":true,"update_menu_item_cache":false,"lazy_load_term_meta":true,"update_post_meta_cache":true,"nopaging":true,"comments_per_page":"50","no_found_rows":false,"taxonomy":"language","term_id":2},"tax_query":{"queries":[{"taxonomy":"language","terms":[2],"field":"term_taxonomy_id","operator":"IN","include_children":true}],"relation":"AND","queried_terms":{"language":{"terms":[2],"field":"term_taxonomy_id"}},"primary_table":"wp_posts","primary_id_column":"ID"},"meta_query":{"queries":[],"relation":null,"meta_table":null,"meta_id_column":null,"primary_table":null,"primary_id_column":null},"date_query":false,"request":"\n\t\t\tSELECT wp_posts.ID\n\t\t\tFROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)\n\t\t\tWHERE 1=1 AND wp_posts.post_parent = 0 AND ( \n wp_term_relationships.term_taxonomy_id IN (2)\n) AND wp_posts.post_type = 'circuit' AND ((wp_posts.post_status = 'publish'))\n\t\t\tGROUP BY wp_posts.ID\n\t\t\tORDER BY wp_posts.post_title ASC\n\t\t\t\n\t\t","posts":[823,952,784,889,864,866,908,907,925,951,870,906,905,914,849,745,989,950,855,949,918,743,871,847,948,947,946,872,873,945,899,874,919,890,944,875,943,876,869,942,848,877,917,888,924,979,891,878,941,767,846,856,904,939,737,887,892,938,956,903,901,861,923,937,742,867,857,879,880,881,913,926,936,900,957,882,935,921,858,845,893,953,853,894,898,883,672,83,859,934,868,884,933,916,915,860,644,723,922,843,886,783,954,911,782,909,932,851,931,955,895,930,929,928,920,927,910,885,897,896,850,912,844,854,852],"post_count":125,"current_post":-1,"in_the_loop":false,"comment_count":0,"current_comment":-1,"found_posts":125,"max_num_pages":0,"max_num_comment_pages":0,"is_single":false,"is_preview":false,"is_page":false,"is_archive":false,"is_date":false,"is_year":false,"is_month":false,"is_day":false,"is_time":false,"is_author":false,"is_category":false,"is_tag":false,"is_tax":false,"is_search":false,"is_feed":false,"is_comment_feed":false,"is_trackback":false,"is_home":false,"is_privacy_policy":false,"is_404":false,"is_embed":false,"is_paged":false,"is_admin":true,"is_attachment":false,"is_singular":false,"is_robots":false,"is_favicon":false,"is_posts_page":false,"is_post_type_archive":false,"thumbnails_cached":false},"query_args":{"post_type":["circuit"],"post_status":["publish"],"ignore_sticky_posts":true,"include_children":false,"orderby":"title","order":"asc","posts_per_page":-1,"paged":1,"fields":"ids"},"items":[850,912,844,854,852],"total_items":[823,952,784,889,864,866,908,907,925,951,870,906,905,914,849,745,989,950,855,949,918,743,871,847,948,947,946,872,873,945,899,874,919,890,944,875,943,876,869,942,848,877,917,888,924,979,891,878,941,767,846,856,904,939,737,887,892,938,956,903,901,861,923,937,742,867,857,879,880,881,913,926,936,900,957,882,935,921,858,845,893,953,853,894,898,883,672,83,859,934,868,884,933,916,915,860,644,723,922,843,886,783,954,911,782,909,932,851,931,955,895,930,929,928,920,927,910,885,897,896,850,912,844,854,852],"current":null,"page_query_var":null,"current_page":4,"items_per_page":40,"items_offset":0,"max_items_count":-1,"filter_fields":[],"sort_field":"","sort_order":"asc","sort_type":""}

Any idea? Could it be something with the wrapping css. I format the paging area as grid.

I just tested this and I don’t seem to be able to replicate it. I created a bunch of dummy content and looped through it with this simple template, and I was able to navigate through the pages with 40 items per page and it all worked as expected.

<ul>
  <Loop type=post paged=40>
    <li><Field title /></li>
  </Loop>
</ul>

<PaginateButtons scroll_top=true />
<PaginateFields>
  Page <Field current_page /> of <Field total_pages />
</PaginateFields>

Does a simple template like the one I’ve added above work for you, or are you still encountering the issue? If my template works, then you’ll want to try simplifying your non-functional template down until you find what element you can add/remove that seems to be causing this issue. That’ll help us identify where the issue lies and we’ll hopefully be able to replicate it. Ideally if you can share the simple possible template where this issue still exists, that will make troubleshooting a lot easier.

Done some more investigation - your code works fine.

The issue seems to be that I create a query with

<Set query=my_query type=post oderby=title order=asc paged=40 />

in one template and call the query in another template.

Update:

It is depending on setting the query in advance. As soon I do that it does the thing.

Aha! Yeah, I’m able to replicate the issue now. That does indeed seem like a bug, so I’ll report that and follow up here when it’s resolved.

Edit: I just gave this a bit more thought and I think there might be something else at play. The paged attribute isn’t a query parameter, so it probably needs to be added when loop is run, not added to the query variable. In other words, the template should be

<Set query=my_query type=post />
<Loop query=my_query paged=3>
...

and not

<Set query=my_query type=post paged=3 />
<Loop query=my_query>

Eliot explained the differents between query parameters and regular attributes here and it’s also mentioned in the docs here. That being said, when I try that the pagination still doesn’t work so I think there’s still a bug here related to paginating query variables. I’ll have someone look into this and also confirm where the paged attribute should be placed.

1 Like

I just heard back from Eliot about the expected syntax and it seems like that hypothesis I mentioned was wrong. All query parameters and attributes should be mentioned in the initial Set query tag, including paged. So the syntax you’re using is correct.

Eliot was able to identify the source of the issue that was causing all that code to appear on the second paginated page and a fix will be released in the next version of the plugin.

2 Likes