How to retrieve wp_ json_encode data from custom WordPress database table
-
Hi,
I have created dynamic add/remove fields in frontend post submission page. I usewp_json_encode
and$wpdb->insert
to insert data into my custom WordPress database table. the system is working perfectly.The data is stored in “reward_details” column of my custom table.. It looks like :
{"reward_amount":["500","250","20000","3000"],"reward_title":["Horse","Cat","Tiger","Monkey"],"reward_description":["Horse Home","Cat Home","Tiger Home","Monkey Home"]}
But however I am not able to retrieve and display the data using
json_decode
. Following is my code:<?php $project_id = $_SESSION['project_id']; global $wpdb; $string = $wpdb->get_results( "SELECT reward_details FROM wpxa_rewards WHERE project_id = $project_id" ); $someArray = json_decode($string, true); $count = count( $someArray ); for ( $i = 0; $i < $count; $i++ ) { ?> <div class="panel panel-default"> <div class="panel-body"> <?php echo $someArray[$i]["reward_title"]; ?> </div> </div> <?php } ?>
I want to retrieve and display data dynamically… Plz help…
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘How to retrieve wp_ json_encode data from custom WordPress database table’ is closed to new replies.