Hello Nigel,
I have a view on the following page : hidden link
I would like to allow the user to filter or at least sort the results based on the average rating of a post (from an external plugin).
The users are rating each post with the integers 1 / 2 / 3 / 4 / 5
-------------------------------------------
1./ Filter the result (optimal solution) :
I added the following code in order to allow the user to filter the results based on the average review of each post.
<label for="wpv-ratings_average">[wpml-string context="wpv-views"]Note Moyenne[/wpml-string]</label>
[wpv-control-postmeta field="ratings_average" type="select" default_label="Note moyenne" format="%%NAME%%" url_param="wpv-ratings_average"]
The problem is that the average result value has two decimals and the possible values are 1 / 1,01 / 1,02 / .... / 4,98 / 4,99 / 5 (please see the attached picture - GREEN)
Is there a solution in order to limit the possible filtered values to 1 / 2 / 3 / 4 / 5 ?
It would mean that a "ratings_average" value of 3,42 would be considered as a 3 and 4,61 considered as a 5 in the filter.
---------------------------------------
2./ Simply Sort the values (secondary option).
If the filtered solution is to complicate to implement, I would like to insert a sorting option at least.
I inserted the following code :
<div class="form-group">[wpv-sort-order type="select" options="desc,asc" label_asc_for_field-ratings_average="Les moins bien notées" label_desc_for_field-ratings_average="Les mieux notées"]
</div>
The filter works perfectly and only shows the posts with at least 1 rating in the ascending or descending order.
My problem is that, my view is sorted by "Date of Post" but sorting code, my results are automatically sorted by an ascending ratings_average value of post. (please see the attached picture - RED)
I basically would like the filter to be active only when a user select a dropdown option "sort result by ascending order" or "sort result by descending order". The filter should not be active if no options are selected.
Can you help me solve this matter please ?
Thank you in advance.
Best regards,
Serge