Reputation: 17
I am using a plugin, using the following code could show user ratings:
<?php $users_rating = RWP_API::get_reviews_box_users_rating( $post_id, $reviews_box_id ); ?>
<?php echo $users_rating; ?>
But instead of showing the actual values, I am getting ARRAY writen on my web page.
Can anyone help me please?
Thank you,
Regards
Upvotes: 0
Views: 114
Reputation: 19318
You need to read the documentation to know how to use the API correctly.
Your call to RWP_API::get_reviews_box_users_rating
tells me you're using the "Reviewer WordPress Plugin" from CodeCanyon.
The first step is looking up that method in the documentation: http://evographics.net/WEB_SERVER/reviewer-plugin-v-3-14-2.pdf
The documentation tells you to expect an array to be returned therefore it's up to you to display those values in a usable format.
$users_rating = RWP_API::get_reviews_box_users_rating( $post_id, $reviews_box_id );
// We're going to skip verifying we got back what was expected for the sake of the answer.
// Loop through each user score and display.
foreach ( $users_rating['score'] as $key => $score ) {
// Example of how an individual score could be displayed.
printf( 'Score %d: %d<br />', $key, $score );
}
Upvotes: 1
Reputation: 300
Based strictly on your example the results of your get_reviews_box_users_rating() method is returning an array. You need to loop through the array itself and echo those values.
foreach($users_rating as $k => $rating){
//IF YOUR ARRAY CONTAINS OBJECTS
echo $rating->userRating;
//IF AN ASSOCIATIVE ARRAY
echo $rating['userRating'];
}
To see the structure of the array being returned you can use this:
print_r($users_rating);
That will let you know if your array is a stdObject Array or an associative array of elements.
Upvotes: 0