Archive Templates Query Loop ignores sort settings (orderby/order) due to $wp_query bypass
Theme / environment
- Theme: Betheme (Muffin Builder) 28.2.1
- Setup: Child theme in use
- WordPress: 6.9.1
- PHP: 8.3
- Affects: Archive templates (
template_typestartingarchive-), Query Loop sections
Summary
When using a Query Loop inside an archive template, the “Order by” and “Order” settings have no effect. The template output follows the main archive query ordering instead.
This appears to be because the builder bypasses the custom WP_Query($q_args) on archive templates and uses the global $wp_query directly, so the Query Loop’s orderby and order values are never applied.
Impact
- Archive templates cannot control sorting via Query Loop settings.
- Users see the sort UI in the builder but it does nothing on archive templates.
Suggested steps to replicate
- Use Betheme 28.2.1 with a default install and at least 10 published posts.
- Create a category (for example “News”) and assign at least 6 posts to it.
- Ensure post titles are clearly sortable (for example “Post A”, “Post B”, “Post C”…), or stagger publish dates.
- In Muffin Builder, create an archive template (template type
archive-postor similar) and set it to display category archives. - Add a Query Loop section to the archive template:
- Query source: Posts
- Order by: Title
- Order: ASC
- Posts per page: 3 (optional, to confirm pagination)
- Visit the category archive on the front end.
Expected
- Posts are sorted by title ascending (A → Z), or according to whatever Query Loop sort is chosen.
Actual
- Posts render in the default archive order (typically date DESC), unaffected by Query Loop order settings.
Root cause
In class-mfn-builder-front.php, the Query Loop code builds $q_args['orderby'] and $q_args['order'], but on archive templates it does:
else if( is_archive() && strpos($this->template_type, 'archive-') !== false ) { global $wp_query; $section_posts_query = $wp_query; }
Because $wp_query is used, the custom $q_args sort settings are ignored.
Workaround / patch (for reference)
Replacing the archive branch to create a new query from the main query vars and overriding orderby and order resolves the issue locally. This keeps archive context (tax/date/author query) while allowing builder sort settings to take effect.
Suggested fix direction
Either:
- Apply the Query Loop sort values to the main query when rendering archive templates (so
$wp_queryreflects the builder settings), or - For archive templates, instantiate a new
WP_Querybased on$wp_query->query_varsand override with the Query Loop’sorderbyandorder.
While waiting for a response from one of our team members, we recommend to check Support Center where it is highly likely that you will find the answer to your question in no time.
FAQ | Video Tutorials | How to