Skip Navigation

[Resolved] Creating a Ranking System to Rank a Custom Post Type from 1-100

This support ticket is created 5 years, 6 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by chrisB-30 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1271533

Hello

I am trying to create a ranking system based on the total of 4 criteria in custom toolset fields.
Each criteria would have a corresponding number between 1-100
Fore instance I would have:

Criteria 1 - 67
Criteria 2 - 42
Criteria 3 - 98
Criteria 4 - 67

Total score - 68.6 (Total divided by 4)

I will have these custom fields on all the entries in a custom post type "Countries"
I would then want to display these Countries in order from highest score to lowest score.

Can you point me in the right direction on how I would go about accomplishing this?

Thanks

#1271853

Hi, there's no calculation system built into Views or Types so you'll have to create something on your own using custom code. Furthermore, if you want to be able to sort or filter a View using that calculated value, the calculated value must be saved as a custom field. Here are some hints.
- To get the raw numeric value from a number custom field, you can use get_post_meta() - https://developer.wordpress.org/reference/functions/get_post_meta/
- To set the raw numeric value based on some calculation, you can use update_post_meta() - https://codex.wordpress.org/Function_Reference/update_post_meta
- In the database, Types fields use the prefix "wpcf-". So if your field has a slug in wp-admin like "criteria-1", then in the database that field key will be "wpcf-criteria-1".
- To calculate a field value automatically whenever the post is saved, you could use the save_data hook. https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

#1272481

Humm that looks way too complicated. I guess I will just add the values manually for now.
Thanks