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
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 );
}
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.
Related
I have a form which where I receive some $_POST data. In a submitAction.php (for example) I did 2 steps, first I assign to a variable what I receive in $_POST for each input field, and second I push the variable to an array of fields; this:
first:
$pais= $_POST['pais'];
$horario = $_POST['horario'];
second:
$fields = array(
'pais' => "eeuu",
'horario' => "pdt",
);
I have simplify the number of fields but In reality I have more. I have an array with the names of the $fields array keys, that came from another part of the application.
The problem is that I am trying to automatize this process, because if not I have to edit this submitAction.php for each form that I have in my application.
I am trying to code a for each statement to iterate and did the assign of the $_POST['whatever'] to the $fields key that match, but I am not sure how to do it.
Any help? Thanks in advance :)
I had some difficulty understanding your question, but I presume that you wanted to take the field names and their corresponding values from the POST request (but only from the fields which you have stated in an array) and assign them to a multidimensional array. The code below should help you.
$keyNames = array("pais", "horario");
$fields = array();
foreach($keyNames as $keyName){
$fields[$keyName] = $_POST[$keyName];
}
I have a custom fields that is actually an array.
I would like to get one single field value from this array.
When I do:
$meta = get_post_meta( get_the_ID(), 'my_fields_array');
and then
var_dump($meta); // debugging
I can see the array
How can I get one single value from this array?
If you just want to get a value from an array instead of using
var_dump
Just echo out the value that you need, starting from 0 e.g.
<?php
$meta = array('Best','Worst','Stuff');
echo $meta[1];
?>
In my case echo $meta[1] = Worst
now do the same for your code,if you just want to see the value that is
I think I've found a solution: the issue is that the custom fields values I need are actually serialized into a string. So if I unserialize them I'm able to get what I need:
$meta= get_post_meta( $post->ID, 'custom_field_array', true );
$myvalues = unserialize( $meta );
echo $myvalues[my_value];
It works
I'm working on the bundle model to check on the quantity of each bundle .. I want to display the error message in array so I can return all the errors at one time. how can I pass array to this line
Mage::helper('bundle')->('msg')? I want to add my errors array instead of message to be like this
Mage::helper('bundle')->($errors). but when I do so it returns array.
if there is also any other solution I'd be grateful :)
if you want to display in forntend site, look like this.
$message = new array();
foreach( $array in $element )
{
...
$message[] = Mage::helper('bundle')->__('msg');
...
}
Mage::throwException(implode(', ', $message));
I'm using checkboxes in Advanced Custom Fields for WordPress. I only have one value set for it, that being a value of 'Yes'
And so I have setup the following test:
<?php if (!in_array('Yes', get_field('banner'))) : ?>
However, for those posts that don't have a value specified, I get the following error:
Warning: in_array() expects parameter 2 to be array, boolean given in
/var/sites/d/dev-chwng.co.uk/public_html/wp-content/themes/chwng/loop-slideshow.php
on line 19
I imagine because for the items where 'Yes' isn't selected, that in turn means there is no array called 'banner' that has been set
I tried putting the whole thing inside a statement of <?php if (get_field('banner')) : ?> which prevents the error, but it stops the script working from how I need it (hard to explain).
Does anyone know how I can determine a value of 'Yes' without throwing an error?
You could additionally (first) verify that it's an array, using is_array():
<?php
$banner = get_field('banner');
if ( is_array($banner) && !in_array('Yes', $banner) ) : ?>
This will make the script move on to the else statement immediately, if get_field() doesn't return an array.
Due to how the WP plugin works, it seems the only way I could get it working how I need it was with
<?php if ( get_field('banner') == '' ) : ?>
I am currently trying to set up an edit page where an order form is populated using json_decode to decode json information that was saved when the form was created. Because the form's size can change I have to create the correct number of inputs so that all the json data will have a place to be displayed. Fortunately as the inputs are numbered this should not be hard to do. Unfortunately I am not sure how to pick the last element of the json information that has been decoded. Currently I am using:
public function getEdit($id){
$order = Order::where('id', '=', $id);
if($order->count()) {
$order = $order->first();
$order->order_serialized = json_decode($order->order_serialized);
foreach($order->order_serialized as $key => $value){
$order->$key = $value;
}
return View::make('orders.edit')
->with('order', $order);
} else {
return App::abort(404);
}
}
to decode the information and it is working splendidly but I need to be able to pick up the last element to be able to find the total number of inputs and am not sure how I could do this without disturbing the foreach loop. Any and all help would be greatly appreciated!! Thank you so much!
You can use the count and toArray methods to find the last item.
$nItem = $order->count();
$aOrder = $order->toArray();
$aLastItem = $aOrder[$nItem-1];
Collections have a last() function to compliment the first() function.