Hello,
Thank you for contacting Rank Math today.
Do you have a custom product CPT or your are using WooCommerce?
If it is the latter, the data is saved by WooCommerce and you can grab the rating data using the following logic:
$product = wc_get_product( $product_id );
$rating = $product->get_average_rating();
If you have a CPT then you can grab the value from the postmeta table by using:
$value = get_post_meta($post->ID,'rank_math_snippet_product_rating', true);
Looking forward to helping you. Thank you.
Thank you, that worked perfectly!
For anybody that has this problem and uses vanilla WordPress (i.e. not WooCommerce), this is how you can get the current rating and the maximum possible rating:
get_post_meta(get_the_ID(),'rank_math_snippet_product_rating', true);
get_post_meta(get_the_ID(),'rank_math_snippet_product_rating_max', true)
And if this only applies to some posts, you can use this if statement:
metadata_exists('post', get_the_ID(), 'rank_math_snippet_product_rating')
-
This reply was modified 3 years, 11 months ago by Dan Jones.
-
This reply was modified 3 years, 11 months ago by Dan Jones.
-
This reply was modified 3 years, 11 months ago by Dan Jones.
Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.
If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.