Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

David

share|improve this question
    
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 '12 at 2:29
add comment

1 Answer 1

Here the trick :D

Replace line 145

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

with

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

Manh

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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