Rename image filename using ‘media_handle_upload’
Question
I need to rename images uploaded by the user when they post on my site.
I have a code that works perfectly to save the image and make it part of the post. But I want the images to be renamed to have the title of the post in their filename.
The code I have:
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
$img_id01 = media_handle_upload( 'img_main', $postID );
update_post_meta($postID, 'img_id01', $img_id01);
0
post-meta, uploads, wp-handle-upload
4 years
2018-09-26T11:30:42-05:00
2018-09-26T11:30:42-05:00 0 Answers
97 views
0
Leave an answer