Your code is ok.
May there went something wrong with the PHP json_decode() function in your server environment. Please test the following code that should decode the JSON string to an array…
var_dump( json_decode( '{"p":{"o":{"uh":0}},"c":[{"p":""}],"h":[{"c":""}],"b":[[{"c":"aa"}]]}', true ) );
It should output this…
array(4) { ["p"]=> array(1) { ["o"]=> array(1) { ["uh"]=> int(0) } } ["c"]=> array(1) { [0]=> array(1) { ["p"]=> string(0) "" } } ["h"]=> array(1) { [0]=> array(1) { ["c"]=> string(0) "" } } ["b"]=> array(1) { [0]=> array(1) { [0]=> array(1) { ["c"]=> string(2) "aa" } } } }
Hi Johann, thanks for the quick reply! 🙂
The code you provided outputted the correct array (as you wrote).
This is my complete code:
single-post page (inside the loop):
$product = new SG_products;
$product->getProductRepeater('measurements', 'content_table', get_the_ID()));
SG_products class:
public function getProductRepeater( $repeater_name, $field_name, $product_id ) {
if ( have_rows( $repeater_name ) ) {
$descriptions = array();
while ( have_rows( $repeater_name ) ) { the_row();
foreach (get_sub_field('taxonomy_association') as $taxonomy_group) {
$descriptions[$taxonomy_group][$field_name] = $this->getTable( $field_name );
}
}
}
return $descriptions;
}
private function getTable( $field_name ) {
$field = get_sub_field($field_name);
var_dump($field);
$table = '<table>';
foreach ( $field['body'] as $tr ) {
$table .= '<tr>';
foreach ( $tr as $td ) {
$table .= '<td>';
$table .= $td['c'];
$table .= '</td>';
}
$table .= '</tr>';
}
$table .= '</table>';
return $table;
}
The output of the var_dump is the json I wrote in the first post.
Any thoughts?
Thanks for the help!
There are to many ) at the end in line…
$product->getProductRepeater('measurements', 'content_table', get_the_ID()));
Anyway, I tested this class and it worked as expected.
Strange
Hi Johann,
I’ve found the error. I’m using a local wp install but with an remote database (dev env). I forgot to sync the plugin folder…
In the admin area everything was ok (since I access it remotely), but testing locally, the wp installation didn’t find the plugin, hence the error…
Sorry for the inconvenience, I need the weekend asap 😛
Thanks once again and keep up the great work!
Nice, this is a topic for the plugins trouble shouting page.
Thanks!