Can somebody please tell me how I can use get_attached_media( 'img', postID );
to
get all the attached images from the post and then display the images?
I need the code that goes after it to get the images.
I'm using this function directly within a page with phpexec plugin installed
my gratitude in advance
wp_get_attachment_image_src() actually returns an array so to retrieve the URL as you are doing in the above example you would need:
For reference parameters
[1]
and[2]
are also the width and height of the created image and you should check for false in case no image is foundAlso the last comment in the above answer is incorrect - it should be 'wp_get_attachment_image_src' as per the example not 'wp_get_attachment_image_url'
get_attached_media returns
WP_Post
type datayou can replace the word 'full' with the size of the image you would like either based on the standard sizes or potentially ones you've added to your theme's
function.php
if you are looking for items other than 'image' you should use
wp_get_attachment_url
instead ofwp_get_attachment_image_url
I believed this is the correct answer:
The statement in another answer
is not syntatically correct and will produce an error.
You can see the values of the array that are available with a
var_dump($images)
.