Skip Navigation

[Resolved] render a number field as rating stars in PHP

This support ticket is created 2 years, 1 month 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.

This topic contains 2 replies, has 2 voices.

Last updated by steffenM 2 years, 1 month ago.

Author
Posts
#2527877

Tell us what you are trying to do?

I wonder if it is possible to render a custom post field of type number directly to a star rating when using PHP to build my loop?
I use PHP/self written short codes to render my wp query loops. Accessing custom post types with types_render_field works like a charm.
So far I created several custom post types, one is called "location-rating" and stores a number. If I would use the toolset blocks library to create my loop, I would have access to a Block called "star rating".
Is there any possibility for me to render the "location-rating" field and define it as a star rating?

Is there any documentation that you are following?
did not find anything regarding this topic so far

Is there a similar example that we can see?
-
What is the link to your site?
local development atm.

#2527923

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

There are quite a few star ratings solutions available for WordPress, and you could try to integrate with one, but given that they typically include the UI for users to rate content rather than just display stars based on an existing field value they are likely overkill for your case.

I think you'll really need to roll your own solution, though you needn't start from scratch, you can adapt someone else's solution, we are basically talking HTML and CSS here.

Here's something I found on codepen after a quick search, for example: hidden link

#2528129

Hi Nigel,

thank you very much for your support. As you mentioned, most of the WP Plugins are just overkill :), so I will then go on implementing my own solution.
Thank you for the codepen. Seems like a good start.

Best regards and have a nice day!
Steffen