Allow users to filter content based on a numerical field value.
|Data source||Where the value lives (taxonomy, custom field, post attribute). If you also set an “Other data source”, this value will be used for the Min limit|
|Other data source||Use this setting if you want to use a separate value for the Max limit|
|Compare type||This setting is only visible and relevant when the
|Fields to show||“Min + Max”, “Exact”, “Min”, or “Max”.
If you use two data sources, it is recommended to set this setting to “Min + Max”. If you choose “Min” or “Max”, only that value is compared. If you choose “Exact”, the comparison will use that value for both the upper and the lower limit of the user range.
If a Number Range facet uses two data sources, the lower value is stored as
facet_value, and the upper value is stored as
facet_display_value in the index table.
There are a few things to keep in mind in this situation:
- If a post has no value set for the first (main) data source field, the post will not be indexed, so it will never appear in the results. The same is true for posts that do not yet have this field set in the database because they have not been saved after adding the custom field in (for example) Advanced Custom Fields.
- If a post has no value set for the second data source field, or if that field has not yet been saved for the first time, the post will be indexed but the value for the post’s range upper limit will then be set to
0. This may lead to unexpected or illogical results, depending on the “Compare type” you have set for the facet.
To prevent the above situations, make sure that if you use two data source fields, all posts actually have two values set.
What happens if a Number Range facet uses two data sources, and a user does not enter a value into the “Min” or “Max” field? It depends on the “Compare type” you have set:
- If the facet’s “Compare type” is set to “Basic”, only the field which has a value entered is used in the comparison.
- If the facet’s “Compare type” is set to “Enclose” or “Intersect”, an empty “Min” field will be compared as
-999999999999and an empty “Max” field as
999999999999. Note that in this case, setting “Enclose” as “Compare type” will lead to 0 results, as the post’s range will never surround these user range values.