Using Dynamic Content in the new Rating element

Hi,

I’m experiencing an issue with the new Rating element.
Through the Dynamic Content button, I’ve set a post-meta value for the star value. The rating element does nothing with it and shows just 0 stars out of 5.
For testing, I’ve used the same post-meta in a text-element: that value shows!

Digging into the code I found that the rating element is capable of handeling post-meta, with is always a string. In rating.php inside the conernerstone/include/views/partials folder on line 21 any string is converted to a float value ($rating_value_float = floatval( $rating_value_content ). Therefore the post-meta format itself could not be the issue.

I can’t seem to find out were the real cause of this issue lies. Any thoughts?

Settings of the text-element:

Settings of the rating-element:

Output:

Hi @dhunink,

Thanks for reaching out.

I can confirm this issue on my end and I added this to our issue tracker. For now, please use number values for the rating since it’s also referencing to the same post.

Thanks!

Hi @Rad!
Thanks for confirming the issue. Is this bug something to be looked into during the current release cycle? If so, that would be awesome. If not I’ve got to look for some other solutions. I need the dynamics, since the post_meta might change every 24 hours.

If it helps: I’d be happy to do some more debugging but right now I’m stuck on figuring out where the variable that’s converted to float is actually coming from. I can’t find a reference anywhere else in the codebase. Any thoughts on that?

Hello @dhunink,

Our developers are now looking to this issue. Once they have fixed it, it will be updated and rolled out in the next release update cycle.

Please bear with us.

That’s great news!

Btw, I can confirm that the value itself seem to be saved correctly. Here’s a copy-paste of the relevant database snippet:

"rating_value_content":"{{dc:post:meta key=\"reviews_aggregated_score_mean\"}}"

That looks correct to me.

I’m not familiar (yet) with the exact way DC works in the codebase, but I’m digging through the code right now to see if I might find anything useful to narrow the issue down a bit further.

Hi @dhunink,

There must be conflict between the Rating element and the Dynamic Content. We will just wait for our developers to figure this out.

Please bear with us.

The .3 update fixed this perfectly for me. Big thumbs up to the team!

Hi @dhunink,

Good to hear that it’s working now. Thanks for reporting the issue. Have a great day!

In the original post I’ve only mentioned dynamic content, but the issue exists with a simple shortcode as well.
Should have mentioned it…

Right now the DC issue is fixed, but a string that’s returned from a shortcode is still not rendering (while it does render in a text element). For testing I used a shortcode that simply returns a string.
Perhaps this is worth looking into when another point-release might be released? Would be much appreciated :grinning:

Hey @dhunink,

I’ll add it to the report by Rad. We couldn’t say if it will be fixed in the next point release though.

Thanks.

Hi,

The report by @Rad was marked as resolved if I understood correctly. Shouldn’t this be a new report instead?

While we’re at it: the ability to add schema markup is really brilliant. Could you pass on my gratitude to @alexander and the other devs? It saves me so much custom coding :grinning:

Hey @dhunink,

That’s not a problem as I tagged @alexander in the report which is connected.

I’ll forward the issue and your message directly to him and the dev team.

Thanks.

Hi @dhunink,

I wanted to share a quick update regarding this issue. The rating fields are just meant to be numeric inputs so they won’t support shortcodes. We opted to support dynamic content in case you wanted to source those numbers from somewhere else.

If you need to do something beyond what the DC fields support, you could setup your own dynamic content hook. This is a bit more involved and takes some custom development but here’s an example:

// Put this somewhere DC is supported: {{dc:my_custom_stuff:thing}}
add_filter( 'cs_dynamic_content_my_custom_stuff', function( $result, $field, $args) {
  
  // $field === "thing"

  
  $result = 'dynamic value';

  return $result;
}, 10, 3 );

Hi @alexander,

I’ve just declared you hero of the month. I did not knew there were filters available for Dynamic Content.
Until now I’ve limited myself to the filters mentioned here and wrote a lot (like several thousand lines of code) to use native WordPress filters/hooks to alter the content of my website. Using Global Blocks I came quite far. I should have done a better search of de codebase; just found the filter in class-dynamic-content. It’s code IS like poetry :slight_smile:

Thanks a million for pointing out the existing of these filters. They absolutely take DC to the next level. I’m going to re-write a lot of code, including those to output more advanced ACF fields through shortcodes, where the could be delivered through DC using these filters.

Thanks @Alexander, your awesome. Have a nice weekend!

You’re welcome @dhunink !
It’s good to know that it has worked for you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.