Is it possible to rename a photo when it is uploaded to a slider?
What I have is a repeater that is an image slider and I have a text field for a stock number. What I’m wondering is if there is a way to rename the photos that are upload uploaded to the slider to have “stocknumber_img_#”?
It is possible to change the file name of an uploaded file during the upload in WP, you can do a search for this and find several solutions, however, it’s not possible to do what you’re looking for. The reason is that the field with the stock number won’t be available until after the image is already uploaded and saved to the uploads folder. When you add an image in ACF the image is uploaded and then then actual value of the field is the image ID that was uploaded.
Giving this some thought, you could rename the file after the upload once the post is submitted. Well, not really rename it exactly, more like replace it. You could create an acf/save_post filter and in this filter
Get the information about the image that was uploaded
I am looking to do something similar, but simpler. I have a front-end form that allows the user to upload an image attachment to their account (separate from their profile pic). So the form would save to post_id of ‘user_123’ (for user ID 123).
Do I need to use this technique in order for the image upload to work, or is it sufficient to have an image field in the form group used in the acf_form?
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users