Skip Navigation

[Resolved] Filters and Sorting In Views

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by sergeP 4 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1507405
Sans titre.png

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

#1508183

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Nigel is on holidays, this is Minesh here and I'll try to help you further.

The thing is that when you add the view's filter for custom field like you added:

[wpv-control-postmeta field="ratings_average" type="select" default_label="Note moyenne" format="%%NAME%%" url_param="wpv-ratings_average"]

It will load the values from the database, that means whatever values stored in the database with the field "ratings_average" it will display those values.

Is there a solution in order to limit the possible filtered values to 1 / 2 / 3 / 4 / 5 ?
=>
There is no way to filter the values comes from the database but if you want to display the custom values it is possible.

If you add the filter as given under:

[wpv-control-postmeta field="ratings_average" type="select" source="custom" url_param="wpv-ratings_average" values="1,2,3,4,5" display_values="1,2,3,4,5"]
</div>

It will display your field with values 1,2,3,4,5.

As per our support policy, we entertain only one question per ticket, lets resolve #1 first and after that lets focus on your 2nd issue.

#1510133

Thank you for your answer Minesh,

Ok, but it means that if I only display the fields 1,2,3,4,5 it will not display the values between (such as 3,33).
If I understand well, there is no way to round the numbers (unless adding some custom code) in order to display the value 3,33 as a 3 and 4,66 as a 5 right ?

Thank you in advance for your help.
Best regards,
Damien

#1512973

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok, but it means that if I only display the fields 1,2,3,4,5 it will not display the values between (such as 3,33).
==>
Yes - that is correct. You can either set the filter to filter the posts less than or equal to or greater than or equal to.

If I understand well, there is no way to round the numbers (unless adding some custom code) in order to display the value 3,33 as a 3 and 4,66 as a 5 right ?
==>
Yes - there is no such option available other than you can add/pass the values as I suggested to your filter shortcode using values and display_values attribute.

 [wpv-control-postmeta field="ratings_average" type="select" source="custom" url_param="wpv-ratings_average" values="1,2,3,4,5" display_values="1,2,3,4,5"]
 
#1513029

Thank you Minesh
My issue is resolved now. Thank you!