The Sort facet type adds a sort box for changing the listing order.
It might seem a bit counter-intuitive that Sort is a facet type, but just like any other facet type, a Sort facet can be added by making a new facet in the FacetWP admin interface.
|Default label||The dropdown label that the user sees by default (i.e. when no sort has been selected).|
|Sort options||The UI for customizing the choices that appear in the sort dropdown. Each row corresponds with a sort choice, allowing you to set:
The following example shows the setup for a sort box containing the default label of “Sort results” and 3 choices (Title DESC, Price DESC, and MPG Highest).
When a Proximity facet is active, the post IDs are automatically sorted (nearest to furthest). This makes it possible to sort results by distance.
To enable sort by distance, create a new sort option and set its data source to
If you want to sort the results by distance on page load, use this custom code.
For numerical sorts like “Price”, the custom field should contain a raw integer or decimal value (with a dot). Fields containing dollar signs, commas, or other symbols won’t work.
For date sorts, the field should contain values in
YYYY-MM-DD HH:MM:SS format. The default “Post Date” and “Post Modified” fields use this format already. But if you’re using a custom field in some other format, it likely won’t work.
If you are using FacetWP with WooCommerce product variations, be aware that sorting by product variation prices is currently not (yet) supported with the Sort facet. The logic of the Sort facet is based on
WP_Query and therefore supports only basic custom fields-based sorting. Product variation prices are unfortunately more complex than that.
If you need sorting by product variation price, you could use WooCommerce’s built-in sort box, which works on the “normal” WooCommerce product archive. FacetWP fully supports WooCommerce product archive pages.