How to save media files under custom folder without changing wp-config.php or changing media settings

Here is simple function to create your own sub directory for every upload. function kv_custom_image_dir( $pathdata ) { $subdir=”/uploads_img”.$pathdata[‘subdir’]; $pathdata[‘path’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘path’]); $pathdata[‘url’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘url’]); $pathdata[‘subdir’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘subdir’]); return $pathdata; } add_filter( ‘upload_dir’, ‘kv_custom_image_dir’ ); From my above code, I changed my images folder as uploads_img, you can change … Read more

Upload file without attaching it to a POST

The $post_id argument for media_handle_upload is used to set the column post_parent for attachment post. Posts without any parent have 0 as post parent, not null. So, use 0 as argument and it will work. If you read Codex page linked above it states: … If you don’t want this media attached to a specific … Read more

wordpress media library shows empty images

Plugins such as Search and Replace can help you to properly fix the URLs in your database. Likewise, consider using backup-and-migration plugins such as BackupBuddy (paid) or Duplicator (free) to properly and more easily move your site (while automatically handling the above search-and-replace operation).

How to upload unknown file type?

You can use this function as you mentioned and you need to learn your file extensions mime type (in example i add svg and xcf upload ability to wordpress) add_filter(‘upload_mimes’, ‘ability_to_upload’); function ability_to_upload($mimes = array()) { $mimes[‘svg’] = ‘image/svg+xml’; $mimes[‘xcf’] = ‘image/xcf’; return $mimes; } Here is a link for mime types list and file … Read more

window.send_to_editor and jQuery .attr() conflicts with multiple custom upload image meta boxes

I did similar thing recently but used the wp.media instead of ThickBox https://codex.wordpress.org/Javascript_Reference/wp.media with the same code from Codex. The only thing to make it work with multiple inputs is to move the frame variable from global scope to click function, so the ‘frame’ will be fresh for each click.