I have an attachment in a post and I want to attach it to another post without detaching it from the first post, using the WP API.
2 comments
Comments are closed.
I have an attachment in a post and I want to attach it to another post without detaching it from the first post, using the WP API.
Comments are closed.
When inside of the media uploaded in the post edit screen, just search for your previously attached media and embed it in your new post.
The relationship between posts and attachments is preserved in the database. While an attachment can only belong to one post, it can still be embedded in many posts without worry.
It is not so simple to do this. In my code change post_parent field from the attachment with new post Id.
If you want to duplicate the attachment and use it in more posts you have to follow the steps here: wp_insert_attachment.Also, it is posible to copy $attach in new object but you have to unset the ID property of this object.