• Resolved kevinator12

    (@kevinator12)


    I have a post that has a an image attachment.

    All I would like to do is get the image ID.

    I tried using get_children(), but I don’t understand the result at all.
    I have found multiple solutions to show me the image, but what I really want is the image ID, or the image URL, without it the image being shown.

    Is there a simple solution to this?

Viewing 1 replies (of 1 total)
  • Thread Starter kevinator12

    (@kevinator12)

    Figured it out.

    The code below creates an array called $child_image which can be easily queried with $child_image[‘ID’] or $child_image[‘guid’]…

    $args = array(
    	'numberposts' => 1,
    	'order'=> 'ASC',
    	'post_mime_type' => 'image',
    	'post_parent' => $post->ID,
    	'post_type' => 'attachment'
    	);
    
    $get_children_array = get_children($args,ARRAY_A);  //returns Array ( [$image_ID]...
    $rekeyed_array = array_values($get_children_array);
    $child_image = $rekeyed_array[0];
Viewing 1 replies (of 1 total)
  • The topic ‘get image id or url for a post’ is closed to new replies.