Title: Access nextgen galleries from php code
Last modified: April 4, 2017

---

# Access nextgen galleries from php code

 *  Resolved [imanc](https://wordpress.org/support/users/imanc/)
 * (@imanc)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/access-nextgen-galleries-from-php-code/)
 * Hi,
    I need to access photos in a gallery from php code. I found the following
   solution:
 *     ```
       <?php 
   
       require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
   
         $gallery_id = 1;
         $imagegallery = new nggdb();
         $images = $imagegallery->get_gallery(1);
       ```
   
 * Is it correct? I see that the nggdb class is in the legacy folder, is there a
   new mode to get the job done?
    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Contributor [photocrati](https://wordpress.org/support/users/photocrati/)
 * (@photocrati)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/access-nextgen-galleries-from-php-code/#post-8992685)
 * [@imanc](https://wordpress.org/support/users/imanc/) – This snippet, in general,
   should help to get you the references you may need:
 *     ```
       $gallery_id     = 3; // for example
       $gallery_mapper = C_Gallery_Mapper::get_instance();
       $image_mapper   = C_Image_Mapper::get_instance();
       $storage        = C_Gallery_Storage::get_instance();
       $gallery        = $gallery_mapper->find($gallery_id);
       $image          = $image_mapper->find($gallery->previewpic);
       var_dump($image);
       var_dump($storage->get_image_url($image, 'thumb'));
       var_dump($storage->get_image_url($image, 'full'));
       ```
   
 * Thanks!
 * – Cais.
 *  Thread Starter [imanc](https://wordpress.org/support/users/imanc/)
 * (@imanc)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/access-nextgen-galleries-from-php-code/#post-8993306)
 * Thank you, now I understand how the plugin works. As reference, with the following
   code I get all images of the gallery with id=1
 *     ```
       $gallery_id     = 1;
       $gallery_mapper = C_Gallery_Mapper::get_instance();
       $gallery        = $gallery_mapper->find($gallery_id, TRUE);
   
       var_dump($gallery->get_images());
       ```
   
    -  This reply was modified 9 years, 2 months ago by [imanc](https://wordpress.org/support/users/imanc/).
    -  This reply was modified 9 years, 2 months ago by [imanc](https://wordpress.org/support/users/imanc/).
 *  Plugin Contributor [photocrati](https://wordpress.org/support/users/photocrati/)
 * (@photocrati)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/access-nextgen-galleries-from-php-code/#post-8997351)
 * [@imanc](https://wordpress.org/support/users/imanc/) – Thanks for sharing!
 * – Cais.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Access nextgen galleries from php code’ is closed to new replies.

 * ![](https://ps.w.org/nextgen-gallery/assets/icon-256x256.png?rev=2083961)
 * [Photo Gallery, Sliders, Proofing and Themes - NextGEN Gallery](https://wordpress.org/plugins/nextgen-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [photocrati](https://wordpress.org/support/users/photocrati/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/access-nextgen-galleries-from-php-code/#post-8997351)
 * Status: resolved