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_type starting archive-), 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

  1. Use Betheme 28.2.1 with a default install and at least 10 published posts.
  2. Create a category (for example “News”) and assign at least 6 posts to it.
  3. Ensure post titles are clearly sortable (for example “Post A”, “Post B”, “Post C”…), or stagger publish dates.
  4. In Muffin Builder, create an archive template (template type archive-post or similar) and set it to display category archives.
  5. 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)
  6. 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:

  1. Apply the Query Loop sort values to the main query when rendering archive templates (so $wp_query reflects the builder settings), or
  2. For archive templates, instantiate a new WP_Query based on $wp_query->query_vars and override with the Query Loop’s orderby and order.

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.

Sign In or Register to comment.
This website uses cookies

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services.

Cookies are small text files that can be used by websites to make a user's experience more efficient.

The law states that we can store cookies on your device if they are strictly necessary for the operation of this site. For all other types of cookies we need your permission. This means that cookies which are categorized as necessary, are processed based on GDPR Art. 6 (1) (f). All other cookies, meaning those from the categories preferences and marketing, are processed based on GDPR Art. 6 (1) (a) GDPR.

This site uses different types of cookies. Some cookies are placed by third party services that appear on our pages.

You can at any time change or withdraw your consent from the Cookie Declaration on our website.

Learn more about who we are, how you can contact us and how we process personal data in our Privacy Policy.

Please state your consent ID and date when you contact us regarding your consent.