1. Home
  2. Docs
  3. Divi Extended Loop
  4. Settings
  5. Order By Queries

Order By Queries

Using OrderBy Queries in Loop Customization

OrderBy Queries give you fine-grained control over how posts are sorted in a loop. Whether you’re building a blog archive, product grid, or custom listing, sorting by fields like publish date, title, or custom meta values helps surface the most relevant content.

How OrderBy Queries Work

Each OrderBy clause defines a sorting rule. You can add multiple clauses to create layered logic—for example, sort by publish date first, then by a numeric custom field like price or priority.

Key Components

1. Multiple OrderBy Clauses

You can stack multiple sorting rules. The order in which clauses appear determines their priority:

  • First clause: Primary sorting rule.
  • Second clause: Used when the first clause results in a tie.
  • Additional clauses: Further tie-breakers.

2. Field

Choose the field to sort by. Available options include:

  • Post ID
  • Author
  • Title / Name / Slug
  • Post Type
  • Published Date / Modified Date
  • Parent Post
  • Random
  • Comment Count
  • Search Relevance
  • Meta Value / Meta Value (Numeric)
  • Post ID Order / Slug Order

3. Direction

Set the sorting direction:

  • ASC – Ascending (e.g., oldest to newest, A–Z)
  • DESC – Descending (e.g., newest to oldest, Z–A)

4. Meta Key (if applicable)

If sorting by a custom field, specify the meta key:

Meta Key: acf_number

Make sure the field exists and is consistently formatted—especially for numeric sorting.

5. Add or Remove Clauses

Use the Add OrderBy Clause button to insert new sorting rules. Each clause can be removed individually with the Remove button, allowing for flexible and precise ordering.

Use Cases

  • Sort posts by publish date, then by a custom priority field.
  • Display products ordered by price (numeric meta field).
  • Prioritize search results by relevance, then by comment count.
  • Randomize post order for dynamic homepage layouts.

Tips for Advanced Sorting

  • Use Meta Value (Numeric) for fields like price, rating, or stock count.
  • Combine Published Date DESC with Meta Value ASC to show recent items with lowest values first.
  • Use Post ID Order or Slug Order when syncing with external systems or manual sort lists.

How can we help?

Submit a Comment