Upload to folder with ID
-
Hello!
Thanks for the great product!
Tell me please
I found this piece of code that uploads images to post date folders:/** * Upload all images for the post to a folder based on the post date (in Y/m format) * * (e.g. if the post was published on June 1st 2017, its images would * be uploaded to /wp-content/uploads/2017/06) * */ function wpai_set_upload_folder_by_post_date($uploads, $articleData, $current_xml_node, $import_id) { if ( ! empty($articleData['post_date'])) { $uploads['path'] = $uploads['basedir'] . '/' . date("Y/m", strtotime($articleData['post_date'])); $uploads['url'] = $uploads['baseurl'] . '/' . date("Y/m", strtotime($articleData['post_date'])); if (!file_exists($uploads['path'])) { mkdir($uploads['path'], 0755, true); } } return $uploads; } add_filter('wp_all_import_images_uploads_dir', 'wpai_set_upload_folder_by_post_date', 10, 4);
It works great! But how I can add a folder with a post ID so that the path is like this /2020/02/6532/
Where 6532 is the post ID on this site after import.I tried to do so:
function wpai_set_upload_folder_by_post_date($uploads, $articleData, $current_xml_node, $import_id) { if ( ! empty($articleData['post_date'])) { $uploads['path'] = $uploads['basedir'] . '/' . date("Y/m", strtotime($articleData['post_date'])) . '/' . $post_id; $uploads['url'] = $uploads['baseurl'] . '/' . date("Y/m", strtotime($articleData['post_date'])) . '/' . $post_id; if (!file_exists($uploads['path'])) { mkdir($uploads['path'], 0755, true); } } return $uploads; } add_filter('wp_all_import_images_uploads_dir', 'wpai_set_upload_folder_by_post_date', 10, 4);
But unfortunately it doesn’t work.
Help me please.
Thanks in advance
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Upload to folder with ID’ is closed to new replies.