DUPLICATE: AJAX pagination on archive templates returns ALL posts since 2.4.4 (query signature mismatch for term context)

Browser: any (reproducible with curl)
OS: macOS
URL: available on request
Video:

bricks-244-ajax-pagination-category-all-posts

Bricks version: 2.4.4 (worked before the update; the same setup returned the correct page via AJAX on 2.4.3 and earlier) WordPress: 7.1.4 · PHP: 8.5.12 · Browser: any (reproducible with curl)

What happens

On a category / tag / custom-taxonomy archive template with a query loop set to “Is main query” and a Pagination element with AJAX enabled, clicking page 2 loads posts from all posts instead of the archive’s term. The page count jumps from the archive’s real count to the count of all posts (in our case 40 → 112 pages). The URL still changes to /category/…/page/2/ and the H1 stays correct, only the loop is wrong.

Opening /category/…/page/2/ directly (full page load) returns the correct page, so only the AJAX path (POST /wp-json/bricks/v1/load_query_page) is affected.

Steps to reproduce

Archive template applied to a category (also reproducible with post_tag and a custom taxonomy).
Query loop: Post, “Is main query” = on, no other query settings.
Pagination element targeting that loop, “AJAX” = on.
Open a category with more than one page, click page “2”.
Result: posts from all categories, pagination recalculated for all posts.

Request / response

The request body sent by the frontend is correct – it carries the archive scope and the signature:

{“postId”:“25”,“queryContextType”:“term”,“queryElementId”:“rpkpl1”,
“queryVars”:“{“category_name”:“recepti/kolaci”,“is_archive_main_query”:true,“orderby”:“date”,“post_status”:“publish”,“paged”:1,“posts_per_page”:“12”,”_bricks_query_signature":“…”}",
“page”:2,“paginationId”:“rpkpg1”,“baseUrl”:“https://…/category/recepti/kolaci/”,“mainQueryId”:“rpkpl1”}

The response updated_query.query_vars has lost category_name:

{“is_archive_main_query”:true,“orderby”:“date”,“post_status”:“publish”,“paged”:2,“posts_per_page”:“12”}

with count: 1337, max_num_pages: 112 (all posts). Sending the body with modified queryVars (e.g. without is_archive_main_query, or with posts_per_page: 3) returns the identical result, i.e. the server is ignoring the frontend query vars entirely.

Where it breaks (from reading the theme source)

includes/elements/base.php (around line 4293): when the page is rendered, the frontend query vars are signed with $query_context_id = Database::$page_data[‘preview_or_post_id’] ?? get_the_ID(). On a term archive this is the term ID (the same value the frontend later sends as postId).
includes/api.php → render_query_page() calls the new get_ajax_query_context() (@since 2.4.4). For queryContextType = term|user it sets up $wp_query->queried_object correctly but returns [‘post_id’ => 0], and that 0 is what gets passed into the bricks/posts/query_vars closure.
includes/query.php → restore_original_query_vars_from_frontend() recomputes the HMAC with post_id = 0. The signature was made with the term ID, so hash_equals() fails and the function silently returns $populated_query_vars (rebuilt from the saved settings).
In Query::run() the main query is deliberately not used for the load_query_page endpoint, and the rebuilt vars contain no taxonomy constraint, so the loop runs an unscoped post query.
In short: the signature is created with the term ID as context and verified with 0. Either the signer should use the normalized context, or get_ajax_query_context() should hand the original ID to the verifier (while still keeping it out of post-meta lookups, which is what the 2.4.4 comment says the normalization is for). The same path is taken for queryContextType = user, so author archives are presumably affected too (not tested here).

Temporary workaround we use

A small bricks/posts/query_vars filter (priority 20) that, only for the load_query_page endpoint and only when the query has is_archive_main_query and the rebuilt vars contain no taxonomy constraint, adds a tax_query for get_queried_object() (which 2.4.4 does set correctly). Turning AJAX off on the Pagination element also avoids the problem.

Thanks for looking into it.

Full request / response (curl)

Bricks 2.4.4 – AJAX pagination on a category archive (Query loop “Is main query” + Pagination AJAX)
Captured 2026-11-01 by clicking page “2” on /category/recepti/kolaci/ (40 real pages, 12 posts/page). Logged-out visitor. Nonce and signature masked.

=== REQUEST ===
POST /wp-json/bricks/v1/load_query_page
Content-Type: application/json
{
“postId”: “25”,
“queryContextType”: “term”,
“queryElementId”: “rpkpl1”,
“previewTemplateId”: “0”,
“componentId”: false,
“queryVars”: “{“category_name”: “recepti/kolaci”, “is_archive_main_query”: true, “orderby”: “date”, “post_status”: “publish”, “paged”: 1, “posts_per_page”: “12”, “post__not_in”: [32120], “_bricks_query_signature”: “<64-hex HMAC as rendered by the page>”}”,
“page”: 2,
“nonce”: “”,
“paginationId”: “rpkpg1”,
“baseUrl”: “Kolači – ReciPeci”,
“lang”: false,
“mainQueryId”: “rpkpl1”,
“activeSearchTemplate”: “0”,
“urlParams”: {}
}

queryVars decoded (as sent by the frontend – archive scope present):
{
“category_name”: “recepti/kolaci”,
“is_archive_main_query”: true,
“orderby”: “date”,
“post_status”: “publish”,
“paged”: 1,
“posts_per_page”: “12”,
“post__not_in”: [
32120
],
“_bricks_query_signature”: “<64-hex HMAC as rendered by the page>”
}

=== RESPONSE (HTTP 200) ===
updated_query:
{
“component_id”: “”,
“instance_id”: “”,
“element_id”: “rpkpl1”,
“element_name”: “div”,
“query_vars”: {
“is_archive_main_query”: true,
“orderby”: “date”,
“post_status”: “publish”,
“paged”: 2,
“posts_per_page”: “12”,
“post__not_in”: [
32120
]
},
“object_type”: “post”,
“count”: 1337,
“max_num_pages”: 112,
“initial_loop_index”: 12,
“is_simulated_loop_context”: false,
“start”: 13,
“end”: 24
}

Note: post__not_in [32120] comes from our own bricks/posts/query_vars filter (excludes the hero post); it is unrelated to the bug.

First post titles in response html (these are the newest posts of the whole site, not of the category):

  • Čokoladni brownies u fritezi na vrući zrak
  • Bobaljke s makom i orasima
  • Okruglice s bananom od samo tri sastojka
  • Kompletan blagdanski ručak uz Tefal Cook4Me
  • Raspucanci bez brašna od samo 4 sastojka
  • Keksi sa marcipanom i brusnicama za još ljepše blagdane
  • Topla salata sa bulgurom, kvinojom, slanutkom i povrćem
  • Heljdoto s bundevom i gljivama by Tefal Cook4Me
  • Krem juha od pečene bundeve i umak za tjesteninu
  • Kremasti kolač s jabukama i rozen korama
  • Punjene pečene jabuke by Tefal Easy Fry Silence
  • Kolač s jabukama, orasima i cheesecake kremom

=== CONTROL: direct full page load of /category/recepti/kolaci/page/2/ (no AJAX) ===
Returns the correct second page of the category (40 pages, e.g. “Domaći sladoled”, “Torta od mrkve”).

=== CONTROL: same request with modified queryVars (no is_archive_main_query / posts_per_page 3 / extra cat=25 / signature removed) ===
Identical response in every case (count 1337, max_num_pages 112) – the server rebuilds the query from saved settings and ignores the frontend queryVars (signature verification fails: signed with term ID as context, verified with 0).

Thanks for the detailed report. This matches the issue tracked here: WIP: Archive Template Issue – Load More Displays Posts from All Categories . An internal fix is merged and should be included in an upcoming release, assuming testing passes. We’ll update that thread once it’s fixed.

For now, disabling AJAX on the Pagination element avoids this issue.