If your theme or another 3rd party plugin provides custom fields (aka post meta) for aggregate ratings, you can hook the ‘wpsso_json_prop_https_schema_org_aggregaterating’ filter to modify the default values. Here’s an example using the ‘average_review’ and ‘count_review’ custom field names (aka post meta).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
add_filter( 'wpsso_json_prop_https_schema_org_aggregaterating', 'custom_aggregaterating', 10, 2 ); function custom_aggregaterating( array $rating, array $mod ) { if ( $mod[ 'is_post' ] && $mod[ 'id' ] ) { $rating_average = get_post_meta( $mod[ 'id' ], 'average_review', $single = true ); $rating_count = get_post_meta( $mod[ 'id' ], 'count_review', $single = true ); $rating[ 'ratingValue' ] = number_format( (float) $rating_average, '2', '.', '' ); $rating[ 'reviewCount' ] = (int) $rating_count; } return $rating; } |
See the $mod variable documentation for more information on the $mod array and its elements.