Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now
2 deleted 6 characters in body
source | link

I have this problem with attaching images and add media.

ADD MEDIA

  1. Go to page
  2. Click on "Add media"
  3. Insert an image
  4. Image shows in editor, but when I go to the page and do the below code it doesn't update.

ATTACH IMAGE

  1. Go to media
  2. find image and attach a page
  3. 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', 'three_images''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?

I have this problem with attaching images and add media.

ADD MEDIA

  1. Go to page
  2. Click on "Add media"
  3. Insert an image
  4. Image shows in editor, but when I go to the page and do the below code it doesn't update.

ATTACH IMAGE

  1. Go to media
  2. find image and attach a page
  3. 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', 'three_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?

I have this problem with attaching images and add media.

ADD MEDIA

  1. Go to page
  2. Click on "Add media"
  3. Insert an image
  4. Image shows in editor, but when I go to the page and do the below code it doesn't update.

ATTACH IMAGE

  1. Go to media
  2. find image and attach a page
  3. 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?

1
source | link

Add media and attach images to pages

I have this problem with attaching images and add media.

ADD MEDIA

  1. Go to page
  2. Click on "Add media"
  3. Insert an image
  4. Image shows in editor, but when I go to the page and do the below code it doesn't update.

ATTACH IMAGE

  1. Go to media
  2. find image and attach a page
  3. 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', 'three_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?