Query, Sorting, and Archives
The Archive Loop block runs a WordPress query that determines which posts appear before visitors touch any filters. Filter selections then narrow that result set over AJAX.
Understanding the base query helps you build archive templates, landing pages, and shop layouts that behave predictably with WPEnhanced Ajax Filter Blocks.
Post type and auto-detect
| Post type setting | Behaviour |
|---|---|
| Auto-detect | On taxonomy or post type archive templates, the loop adopts the current archive context (e.g. category archive limits to that category) |
Specific type (post, product, CPT) | Always queries that type regardless of page context |
Use auto-detect when placing Archive Loop on FSE archive templates. Use an explicit post type on custom landing pages built in the block editor.
Post count, offset, and status
- Post count — Items per AJAX page (pairs with pagination mode)
- Post offset — Skip first N posts (featured row above main loop)
- Post status — Usually
publish; change only for specialized workflows
Include and exclude
Under Loop options, scope the base query:
Include
- Categories, tags, custom taxonomies (with AND/OR term logic)
- Custom meta key/value
- Authors
- WooCommerce: on sale, featured, stock status, price range, minimum rating
Exclude
- Categories, tags, taxonomies, meta
- Specific product IDs
On load
Pre-filter to terms when the page opens—e.g. only Events category—while still letting visitors change filters.
Include current terms on archive pages merges the viewed taxonomy term into the query automatically.
Include/exclude defines the ceiling for filters. A Filter Posts Item cannot show products outside the base query unless the query is widened.
Sorting
Loop options → Sorting configures primary and optional secondary order:
| Sort field | Use case |
|---|---|
| Date (published) | Latest first (default blogs) |
| Title | A–Z directories |
| Menu order | Manual CPT ordering |
| Random | Spotlight rotation |
| Modified date | Recently updated content |
| Comment count | Popular posts |
| Custom field / meta | Price, score, event date stored in meta |
| ACF field (Pro) | Sort by ACF value with type-aware comparison |
| Date picker fields | Event or availability dates |
Set Order ASC or DESC for each level. Secondary sort resolves ties (e.g. sort by date, then title).
Published date methods
Advanced date sorting supports:
- Default published date
- Custom day window (posts from last N days)
- ACF or date-picker end fields for ranges
Sticky posts
Sticky posts behaviour controls whether sticky posts float to the top, are included normally, or excluded—matching WordPress sticky post expectations on blog archives.
Main loop flag
Mark one Archive Loop as Main loop per filter panel target. Secondary loops can show related content with separate queries while one primary loop receives filter AJAX.
Advanced multi-loop wiring: Filter panel and loop.
Relationship and related content (Pro)
Related posts, ACF relationship, and advanced display types require WPEnhanced Ajax Filter Blocks Pro.
Pro query modes can show:
- Posts related to the current post by category, tag, taxonomy, or ACF
- Linked posts via ACF relationship fields
- Grouped results by taxonomy
Free plugin queries focus on standard archives and explicit include/exclude rules.
Archive templates in block themes
When building Templates → Archive in the site editor:
- Insert Archive Loop with post type Auto-detect
- Enable Include current terms if filters should respect the archive slug
- Place Filter Posts in the template sidebar or above the loop
- Match Filter Posts post type to the archive post type
Filters AJAX-update inside the template without replacing WordPress’s native archive URL structure.
Query + URL sync interaction
URL sync parameters apply on top of the base query. A shared link encodes visitor filters; the base query still comes from block settings on the server.
If a shared link returns empty results, check whether include/exclude on Archive Loop conflicts with URL parameters.
WooCommerce catalog queries
For product archives:
- Set post type Product
- Use Shop Style loop template
- Base query can pre-limit to a category; attribute filters narrow further
- Suppress filters option (when available) controls whether WooCommerce’s default catalog filters merge with the query—test with your attribute plugins
Integration details: WooCommerce integration.
Testing query behaviour
- Configure Archive Loop without Filter Posts—verify base results on front end
- Add include rules one at a time; confirm counts match expectations
- Add Filter Posts items; confirm AJAX narrows within base query
- Test sort order after filter changes—sort applies to filtered subset
What's next
- Archive Loop block — Settings reference
- URL sync and shareable filters — Parameters on top of query
- Advanced loop queries — Pro relationship modes