I have this problem with attaching images and add media.
ADD MEDIA
- Go to page
- Click on "Add media"
- Insert an image
- Image shows in editor, but when I go to the page and do the below code it doesn't update.
ATTACH IMAGE
- Go to media
- find image and attach a page
- This works ok, but once that image is attached to that page I cannot attach it to another
CODE
$attachments = get_attached_media( 'image', $page_id);
$images = array();
foreach ($attachments as $attachment)
{
$image = wp_get_attachment_url($attachment->ID);
if($image)
$images[] = $image;
}
wp_localize_script( 'custom-js-script', 'images', $images);
1. I want to use add media because I can then I can re-use images on different pages BUT IT DOESN'T WORK how can I get the images as the above code?
2. If I can't do the above how can I re-use attachments?