Skip to content

Sort numeric custom fields by value#517

Merged
sorinmarta merged 2 commits into
masterfrom
fix/numeric-field-sort
Jul 9, 2026
Merged

Sort numeric custom fields by value#517
sorinmarta merged 2 commits into
masterfrom
fix/numeric-field-sort

Conversation

@sorinmarta

@sorinmarta sorinmarta commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

fixes Strategy11/business-directory-premium#90

Validated numeric fields now sort by value across sortbar and default directory queries through shared numeric-aware orderby handling.

Cast validated numeric sortbar fields after whitespace removal so values like 6, 50, and 500 order correctly.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The sortbar_orderby() function was modified to introduce a $numeric_sort flag that determines whether a meta-derived sort field should use a numeric-safe REPLACE/+0 expression instead of the existing get_space_replace() ordering logic.

Changes

Sortbar Orderby Numeric Handling

Layer / File(s) Summary
Numeric sort flag and orderby clause generation
includes/class-query-integration.php
Adds a $numeric_sort flag computed from field expression comparison and numeric type check, then conditionally builds the orderby clause using a REPLACE(..., ' ', '') + 0 numeric expression or the existing get_space_replace() path.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: sorting numeric custom fields by value.
Description check ✅ Passed The description is directly related to the change and accurately describes numeric-aware sorting.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/numeric-field-sort

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sorinmarta sorinmarta added the run analysis Runs phpcs and phpunit label Jul 9, 2026
Route default and sortbar ordering through one numeric-aware helper so validated numeric fields sort correctly across directory queries.
@sorinmarta
sorinmarta merged commit 16e945b into master Jul 9, 2026
5 checks passed
@sorinmarta
sorinmarta deleted the fix/numeric-field-sort branch July 9, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run analysis Runs phpcs and phpunit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant