I'm trying to upload some associated media to a custom post type.
Using file_put_contents()
I'm uploading an image and trying to set an ACF image field to be the path to that file.
But reading the documentation I apparently need to supply an attachment_id
as part of the update_field
parameters. However, if I insert the image with wp_insert_attachment
(to get an attachment id) it's going to be set as the featured image, will it not?
How can I get an attachment_id without overriding the pre-existing featured image?
file_put_contents
and you should look up the ACF image field documentation, this stack isn't a place to get help with ACF, 3rd party plugin dev support is offtopic herewp-content/uploads
does not make them appear in WordPress, there are already functions provided for sideloading files in, either from remote URLs, or uploads, that will take the file and put it where it needs to be while respecting the settings in WP Admin, creating the attachment post, filling in its metadata and firing al the necessary hooks