0
votes

I'm sending array meta box data using update_post_meta like below. However I cannot seem to output the post meta array value into an empty input. The meta is being stored correctly.

if( get_post_meta( $post->ID, 'date-meta', true ) ) {
    $date_info = get_post_meta( $post->ID, 'date-meta', true );
}

My input field looks like this:

<input type="date" class="widefat" name="vp-date" id="vp-date" value="<?php echo $date_info['vp-date']; ?>" />

I also get a notice which traces back to the if get_post_meta function above. It says:

Trying to get property of non-object in

Any help would be great.

Thanks

1
Can you update your question to include more code giving us context? The answer to this depends on where you're using the code.Nathan Dawson

1 Answers

0
votes

That error message means that the $post is $post->ID is not an object. I don't know what script you are in but try putting

global $post;

above the if.

Making it

global $post;
if( get_post_meta( $post->ID, 'date-meta', true ) ) {
    $date_info = get_post_meta( $post->ID, 'date-meta', true );
}