Ran into a problem with an image upload part of a theme feature.

The code uploaded at http://pastebin.com/Qnn2D36N (that's the entire script for adding the meta boxes) generates custom meta boxes on posts and pages, one of which has a media upload button.

On some installs it works as expected, on others going through the process works until clicking the "Insert into Post" button on the pop up media uploader. Goes back to the post, but the URL to the image isn't added to the form. On a localhost install I have multiple WordPress installations for testing and some work, others don't. On live sites on the same server, some work and some don't. I don't know why, on a clean install with no plugins installed it didn't work.

The code can be added to the TwentyEleven function.php file and it works with the same problems as I'm experiencing in the theme (Stallion) I develop, which suggests the problem is within the code.

With Debug mode on the media upload pop up window after clicking Media Library shows the following notice:

Notice: Undefined index: post_id in C:\wamp\www\0000000000\wp-admin\includes\media.php on line 1755

I get this notice on live sites, both sites that work and don't so it might not be the issue.

Viewing source of where the notice is located shows the post_id isn't part of the code, I see this:

<input type="hidden" value="0" name="post_id"/>

When viewing source of the media uploader when using the media uploader as part of the post (to add an image to a post normally) the post_id is located within value="".

I'm trying to remove this PHP notice to rule it out as the cause, I've tried adding "global $post_id;" in various parts of the script but no joy.

I'm stumped what to try next.


  • Have spent hours looking for a solution with no joy so tried a different technique for generating meta boxes (better solution) and the new technique isn't working on one of the test sites. Not extensively tested yet (just two test sites), but looks like it wasn't the code after all, guess I have a conflict elsewhere, typical hey :-)
    – David Law
    Mar 15, 2012 at 2:29

1 Answer 1


Here the trick :D

Replace line 145

tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');


tb_show('', 'media-upload.php?post_id=1&amp;type=image&amp;TB_iframe=true');


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.