The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Get aggregated rati...
 
Share:
Notifications
Clear all

Get aggregated rating for a post

8 Posts
2 Users
0 Reactions
1,335 Views
Posts: 22
Topic starter
(@zoker)
Eminent Member
Joined: 3 years ago

Hello there,

I have this kind of article rating for a custom post type:

image
image

Now I need a php function, that returns me the aggregated rating from all three rating fields for all ratings for one specific post object. 

So something like one rating for the whole post. 

Example two ratings for one post:

  1. Design: 2/5, Usability: 3/5, Speed: 5/5 (avg. 3/5)
  2. Design: 5/5, Usability: 5/5, Speed: 5/5 (avg. 5/5)

So the overall rating for this post would be 4/5.

Something similar to the Aggregate Rating used for the Google schemas.

So I suppose since you need this value for the Google Schema, there is a function, that returns me the rating value (like post_rating( $post ) or something).

 

Thanks you very much!

Regards,

Florian

7 Replies
Asti
Posts: 7666
 Asti
Support
(@asti)
Illustrious Member
Joined: 7 years ago

You should use the same wpdiscuz_rating_schema hook and make the customization yourself. 

Reply
Posts: 22
Topic starter
(@zoker)
Eminent Member
Joined: 3 years ago

But how can I get the rating value on any page for a specific post? 

For example using a shortcode to display the rating of post with the id 123.

Because the schema filter only defines how the output schema in the source code will look like, right? 

Reply
Posts: 22
Topic starter
(@zoker)
Eminent Member
Joined: 3 years ago

Or to say it in other words: I want to use the ratingValue (within the schema)

Or to even more precise: I want the $avarage value from this function:

image
Reply
1 Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7666

@zoker,

For example using a shortcode to display the rating of post with the id 123.

You can add the post_id attribute in the shortcode: 

[ wpdrating metakey="all" show-lable=true show-count=true show-average=true itemprop=true post_id="123" ] 

It'll display the average rating(included all rating fields) for the current post.  

Reply
Posts: 22
Topic starter
(@zoker)
Eminent Member
Joined: 3 years ago

Unfortunately I can't see the shortcode :/

image
Reply
2 Replies
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7666

Please check it again.  

Reply
(@zoker)
Joined: 3 years ago

Eminent Member
Posts: 22

@asti Thanks for the provided shortcode, but with that I only get something like this:

image

When you have a look at my site, you can see, that on the frontpage, some items have a rating (the 4.0 in the top left corner):

image

That's what I need. So I just need the value in decimal form, like 3.5 / 2.9 / 5.0 etc. 

And for that I don't that this shortcode is not suitable. 

Reply
Share: