So I have run into a little glitch. i have a custom path for uploads and it works. the files get saved to the right place, etc. The problem I have is the ‘widget box’ in the admin section. immediately after uploading and setting the uploaded image as the featured image, it show up in the preview, instead of
www.blog.com/blog/uploads/POST_ID/image_name.png
it is showing
www.blog.com/blog/uploads/image_name.png
The path is broken. Again I am new to WP… is there a filter for the admin ‘widget box’s?
The path I get back is:
<img width="266" height="145" src="http://mysite.com/blog/wp-content/uploads/image-350x192.png" class="attachment-266x266" alt="the title" title="the title">
But where the image resides is:
<img width="266" height="145" src="http://mysite.com/blog/wp-content/uploads/<POST_ID>/image-350x192.png" class="attachment-266x266" alt="the title" title="the title">
I cant add an image because of my rep so far… it appears in the same column as tags
and categories
in the admin area. It is a custom widget
for this theme.
update
function media_upload_dir($upload) {
if(!isset($_REQUEST['post_id']))
return $upload;
$id = $_REQUEST['post_id'];
if (isset($_REQUEST['post_id'])) {
$upload['path'] = "/path/www/blog/wp-content/uploads/" . $id;
$upload['url'] = "http://site.com/blog/wp-content/uploads/" . $id;
$upload['basedir'] = "/path/www/blog/wp-content/uploads/" . $id;
$upload['baseurl'] = "http://site.com/blog/wp-content/uploads/" . $id;
if (!file_exists("/path/www/blog/wp-content/uploads/" . $id)) {
mkdir("/path/www/blog/wp-content/uploads/" . $id, 0777);
}
}
return $upload;
}
add_filter('upload_dir', 'media_upload_dir');
cheers.bo
This is not a answer, is an extended comment with the link to the solution.
First, while testing, one of my test sites wasn’t showing the Featured Image uploaded to the folder
/wp-content/uploads/POST_ID/image_name.jpg
. Same problem as the OP.But, it was not displaying any path to the image. And the bug was that the installation where I was testing is full of hacks (my main WPSE testing base). As soon as I went to a stable installation everything worked.
So, if your problem persist, do a full troubleshooting:
http://wordpress.org/support/topic/troubleshooting-wordpress-33-master-list
Also, Robert, when asking a question please provide all the elements that a person who is willing to help will need to understand and effectively answer it.
Side notes to your code:
mkdir
is not necessary, WordPress handles thiswp-content
, you can use the constants WP_CONTENT_DIR and WP_CONTENT_URLBest regards and good luck!