- This topic has 43 replies, 4 voices, and was last updated 3 years ago by
Bernardas.
-
AuthorPosts
-
February 27, 2023 at 9:35 am #2548930
David
StaffCustomer Support1. You would remove that snippet.
And use this instead:function make_star_bar() { $rating = get_post_meta( get_the_ID(), 'rating', true ); if ( $rating ) { $color = '#f00'; $prefix = 'star-bar-'; $uniqueClass = uniqid($prefix); $percentage = 100 * $rating / 5; $html = '<span class="'.$uniqueClass.'">★★★★★</span> <style> .'.$uniqueClass.' { background: linear-gradient(90deg, '. $color . ' ' . $percentage .'%, rgba(0,0,0,0) '. $percentage.'%); color: rgba(0,0,0,.2); background-clip: text; -webkit-background-clip: text; color: rgba(0,0,0,.2); } </style> <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Rating", "ratingValue": "' . $rating . '", "bestRating": "5", "worstRating": "1" } </script> '; return $html; } } add_shortcode('star_bar', 'make_star_bar');2. Then create a Block Element Hook in Appearance -> Elements:
https://docs.generatepress.com/article/block-element-hook/
2.1 Add your Content and the
[star_bar]shortcode to the element.
2.2 Set the Hook toafter_entry_title
2.3 Set the Display Rule Location to where its required eg. Post > All Posts3. Publish that Element.
4. Now you need to create a Custom Field on your post called:
rating– which is where you will add the rating value for each post.February 27, 2023 at 2:02 pm #2549220Bernardas
Unfortunately, it not working despite completing all 4 steps… Only showing [star_bar]. I also noticed the star rating appears if I add the shortcode [star_bar stars=”2.6″] directly to the post, although it takes the value from the custom field now ( I add the shortcode [star_bar stars=”2.6″], but it shows 4 stars entered in custom field).
February 28, 2023 at 3:14 am #2549676David
StaffCustomer SupportDid you remove that other function ? And clear any caches ?
February 28, 2023 at 3:43 am #2549713Bernardas
Yes, here are the screenshots:
https://ibb.co/Gc9m5Q7
https://ibb.co/ZVLYVt7
https://ibb.co/y0WQpJN
https://ibb.co/QJLjtmz
https://ibb.co/Nrn6wXcFebruary 28, 2023 at 9:15 am #2550244David
StaffCustomer SupportWhat i mean is, do you still have the other snippets saved anywhere ?
February 28, 2023 at 1:02 pm #2550497Bernardas
nope, just tried to test if the new snippet works with the old shortcode [star_bar stars=”2.6″] and it did. Anyway it’s not working with Custom Field: rating
March 1, 2023 at 4:09 am #2551146David
StaffCustomer SupportI tested the steps i added here:
https://generatepress.com/forums/topic/star-rating-system/page/3/#post-2548930
And this my ACF Field:
And that works as intended using the
[star_bar]shortcode.So i am not sure why it won’t work for you.
March 1, 2023 at 6:14 am #2551287Bernardas
Still not working;/// Where do you put the actual rating value, and in what format? E.g I’m trying to add 4.0 or 4 in the custom field but it doesn’t change anything…
March 1, 2023 at 7:16 am #2551362David
StaffCustomer SupportMarch 1, 2023 at 8:18 am #2551598Bernardas
My settings are the same, although I also tried to test for 1 post only. And nothing has changed, I have the same issue, the [star_bar] appears instead of the visual star rating…
March 1, 2023 at 8:52 am #2551627David
StaffCustomer SupportIf you want to raise a new topic, and use the Private Information field to provide me an admin login i can take a closer look.
March 10, 2023 at 6:57 am #2562917Bernardas
Hey David, are you still available for help?
March 10, 2023 at 7:09 am #2562926David
StaffCustomer SupportIf you can raise a new topic, where you can share a link to the site then i can take a look.
I cannot say i can make it work, as it iss custom development. But i am happy to look.March 10, 2023 at 7:29 am #2562947Bernardas
The new topic with private info created.
-
AuthorPosts
- You must be logged in to reply to this topic.

