Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Notice: Undefined index: id WordPress

  • SOLVED

I have a plugin I'm working on and I'm getting this error in debug mode:

Here's the code leading up to the error line:


function mytheme_show_box( $post, $mb_id) {
global $meta_boxes, $post, $post_id;

// Use nonce for verification
echo '<input type="hidden" name="mytheme_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />' . "\n";

echo '<div class="optinpage">' . "\n";

foreach ($meta_boxes as $meta_box) {
if ($meta_box['id'] == $mb_id['id']) :
foreach ($meta_box['fields'] as $field) {
// get current post meta data

$meta = get_post_meta($post->ID, $field['id'], true);


This is the line which is kicking out the error:
$meta = get_post_meta($post->ID, $field['id'], true);

Please help!



Answers (6)

2011-11-24

Utkarsh Kukreti answers:

One of your meta box fields doesn't have an id defined. Could you post the part where you're declaring the meta boxes?


Armand Morin comments:

That was it. I'm didn't have an 'id' listed for a certain array. Thanks.

2011-11-24

Christianto answers:

Hi,

do you pass an array for $meta_boxes
global $meta_boxes

Check to see if 'id' exist in the array..



<em>edit: wrong variable :D</em>

2011-11-24

Nilesh shiragave answers:

Instead if id use name

$meta = get_post_meta($post->ID, $field['name'], true);

2011-11-24

Luis Cordova answers:

oh no this is just a warning

you have many of those from plugins because they forgot to initialize some variable

bud DO NOT WORRY TOO MUCH

they are not harmful, they are NOT ERRORS!

Notice: Undefined index: id

feel free to move forward

2011-11-24

Julio Potier answers:

Hello !

First try this :
$meta = get_post_meta($post->ID, $field['ID'], true);

Then if does not work try this :
function mytheme_show_box( $post, $mb_id) {
global $meta_boxes, $post, $post_id;
<em><strong> wp_die( var_dump( $meta_boxes ) );</strong></em>
// Use nonce for verification
...


And paste us the result.

See you soon !

2011-11-24

Just Me answers:

it seems $meta_boxes is passed the right way otherwise you wouldn't end up in the if-loop.

Can you share the structure of your $meta_boxes array?

Did you try to echo/print_r() the variables you are using, to check if they are available?