Home Forums Backend Issues (wp-admin) Rename media on post save Reply To: Rename media on post save

  • You cannot rename during the saving of the post. ACF uses the WP native upload. Files and images are uploaded and named when they are added.

    I do not have any examples of doing what you want but here is an outline of what would need to be done in ACF to rename the file on upload in ACF

    • First you would need to make sure that the other fields are completed before an image can be added, and potentially that the fields cannot be altered.
    • You will need to add custom JS and use the ACF JS API using an undocumented hook in the API “prepare_for_ajax” data = acf.applyFilters('prepare_for_ajax', data);
    • Using a filter you would have to get the values of the other fields and add them to this ajax data.
    • This data will then be available in $_POST during the file upload process and then you can use these values in the processed described in some of those posts.

    I honestly don’t know how you would rename the files in WP each time the other fields are changed and the post is updated. I have looked and I can’t find much in the way of examples of doing this. If I had to do this I would probably look at the code in other plugins that make it possible to rename a file after it is uploaded and see how they do it and adapt that for use in an acf/save_post action.

    This looks somewhat promising