I am trying to change default values inside array in custom field.
But I am getting error "PHP Fatal error: Uncaught Error: Cannot use string offset as an array" when I try to change the value using following code.
Strangely I use this code in default page template and it works there when I statiscally provide the post id..
but gives error for following code
add_action('pending_to_publish', 'oj_publish_campaign',10 ,1);
function oj_publish_campaign($post) {
global $wpdb;
$t = get_post_meta( $post->ID, '_give_donation_levels', true );
$t[0]["_give_amount"] = 25.00; // getting error here
$t[1]["_give_amount"] = 65.00;
$t[2]["_give_amount"] = 100.00;
$t[3]["_give_amount"] = 250.00;
$t[4]["_give_amount"] = 650.00;
update_post_meta( $post->ID, '_give_donation_levels', $t );
}
this is how the initial array for the custom field looks like
And the strange thing is that it works inside a page-template i.e
if I create a page "Test" and assign it the following template and just load the page , it updates the fields as required
/*
Template Name: Test
*/
get_header();
while ( have_posts() ) : the_post();
$p = 2234;
$t = give_get_meta( $p, '_give_donation_levels', true );
echo "<pre>"; var_dump($t);echo "</pre>";
$t[0]["_give_amount"] = 25.00;
$t[1]["_give_amount"] = 65.00;
$t[2]["_give_amount"] = 100.00;
$t[3]["_give_amount"] = 250.00;
$t[4]["_give_amount"] = 650.00;
update_post_meta( $p, '_give_donation_levels', $t );
endwhile; // End of the loop.
get_footer();
Can anyone please help me with this
thanks in advance