Summary
Since 2.4.4, AJAX pagination (load_query_page) on term archives loses the archive’s term constraint when the query loop uses “Is main query”. Page 1 is correct. After clicking page 2, the loop shows all posts of the post type, and the pagination switches to the total page count of the whole post type.
Loading /…/page/2/ directly works. Only the AJAX request is affected.
Environment
- Bricks 2.4.4 (parent theme, child theme active)
- WordPress 7.1.4, PHP 8.4
- Reproduced on a production site and on a local copy of it
Steps to reproduce
- Create an archive template with the condition Archive type: Term (e.g. all terms of a taxonomy).
- Add a query loop (plain block or component instance) for a post type. Set Is main query (
is_archive_main_query) to on and add no taxonomy settings to the query. - Add a Pagination element for that query (or
main) and enable AJAX. - Open an archive of a term that has more than one page of posts but fewer posts than the whole post type.
- Click page 2.
Expected
Page 2 of the term’s posts, with the pagination count for the term.
Actual
- The loop shows page 2 of all posts of the post type (term constraint gone).
- The pagination shows the page count of the whole post type (in our case 2 pages → 90 pages).
- The archive title is unaffected and still shows the term name.
The request body is correct: it contains "queryContextType":"term", "postId":"<term_id>" and the term in queryVars (e.g. "semester":"class-of-fall-2026"), plus _bricks_query_signature.
Cause
The signature on the frontend query vars is created and verified with different context IDs on term (and user) archives.
Signing: includes/elements/base.php (~L4293)
$query_context_id = Database::$page_data['preview_or_post_id'] ?? get_the_ID();
Query::sign_frontend_query_vars( $query->query_vars, $this->uid, $query->object_type, $query_context_id, $query_settings );
On a term archive, preview_or_post_id is the term ID.
Verification: includes/api.php, render_query_page(). The handler takes the post ID from get_ajax_query_context(), which ends with:
// api.php ~L2479, term / user context
return [ 'post_id' => 0 ];
That 0 is passed into Query::restore_original_query_vars_from_frontend() (includes/query.php ~L3545). It recomputes the HMAC with post_id = 0, which never matches the signature created with the term ID. The function then falls back to the server-built query vars:
if ( ... ! hash_equals( self::frontend_query_signature( ..., $post_id, ... ), $signature ) ) {
return $populated_query_vars;
}
For a loop with Is main query, the server-built vars contain only the saved settings (post type, order, …), so there is no term constraint. That produces the unfiltered result.
Verified by recomputing the signature in-process: it matches with the term ID and does not match with 0. Replaying the request through rest_do_request() shows the restore step returning vars without the taxonomy key.
Suggested fix
Use the same context ID on both sides for term / user contexts. For example:
- verify with the context ID the request referred to (the term/user ID resolved in
get_ajax_query_context()), keepingpost_id = 0only for rendering, or - sign with
0on the frontend when the current page type is a term or user archive.
Workaround
Disable AJAX on the Pagination element of term-archive templates. Regular /page/n/ links render correctly.
Scope on our site
All term-archive templates whose loop uses Is main query together with AJAX pagination are affected. Post-type archives, pages, single templates and the search results template work, because they use the post context, where both sides use the same ID.