WordPress.org

Ready to get started?Download WordPress

Forums

Array of images for a gallery (1 post)

  1. microsnob
    Member
    Posted 2 years ago #

    Hi, Im trying to get an array of images all the wordpress posts and all I am getting is the newest image from the last post, not all of them.

    global $post;
    
    		$photos = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC') );
    
    		$results = array();
    
    		if ($photos) {
    		    foreach ($photos as $photo) {
    		    $keys [] = $photo->ID;
    		    $captions [] = $photo->post_excerpt;
    		    $descriptions [] = $photo->post_content;
    		        // get the correct URL for the selected size
    		        $results[] = array(image => wp_get_attachment_url($photo->ID, 'full'), title => '', url => '');
    		    }
    		}
    		return str_replace('\/', '/', json_encode($results));
    		}

    could anyone tell me what is wrong?
    thanks

Topic Closed

This topic has been closed to new replies.

About this Topic