Title: Display a user&#039;s gallery
Last modified: August 20, 2016

---

# Display a user's gallery

 *  Resolved [hnb](https://wordpress.org/support/users/hnb/)
 * (@hnb)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-a-users-gallery/)
 * Hi there,
 * i have to implement a gallery system where authors can create galleries and manage
   them (i modified a bit the code to display only theirs in the manage menu). So
   far so good, but i have to create a page for each authors and display their galleries,
   which is apparently not possible using shortcodes. So, before starting to develop
   anything i wanted to know if anyone found a solution and was willing to share
   it 😉
 * Thanks a lot,
 * HnB.
 * [http://wordpress.org/extend/plugins/nextgen-gallery/](http://wordpress.org/extend/plugins/nextgen-gallery/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [hnb](https://wordpress.org/support/users/hnb/)
 * (@hnb)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/display-a-users-gallery/#post-3349515)
 * Hi, it’s me again i found a solution for my problem and i wanted to share it :
 * I decided to assign an album to a user using a new table :
 *     ```
       CREATE TABLE wp_user_album(
       	id INT PRIMARY KEY,
       	user_id INT NOT NULL,
       	album_id INT NOT NULL,
       	FOREIGN KEY (user_id) REFERENCES WP_USERS(ID)ON DELETE CASCADE,
       	FOREIGN KEY (album_id) REFERENCES wp_ngg_album(id)ON DELETE CASCADE
       );
       ```
   
 * The assignation will be done manually on phpmyadmin for instance.
 * Then i created a function which i hooked on the action ‘ngg_created_new_gallery’
   which is right after the creation of a new gallery. You can drop this at the 
   bottom of the admin/functions.php :
 *     ```
       /**
       * Add a gallery automatically in the user's album (set manually in the table wp_user_album)
       * @param: $galleryid Id of the gallery created
       * Hooked to the action 'ngg_created_new_gallery', return nothing
       */
       add_action('ngg_created_new_gallery', 'add_gallery_to_user_album', $galleryid);
       function add_gallery_to_user_album($galleryid){
   
       	global $wpdb;
   
       	//Get the gallery
       	$gallery = nggdb::find_gallery($galleryid);
   
       	//Get the user id
       	$user_id = $gallery->author;
   
       	//Get the album of the user
       	$user_album = $wpdb->get_row($wpdb->prepare("SELECT * from {$wpdb->prefix}user_album where user_id = %d", $user_id), ARRAY_A);
       	$album = nggdb::find_album($user_album['album_id']);
   
       	//If the user has an album
       	if($album != null){
   
       		//Create an array with the new gallery id
       		$new = array($gallery->gid);
   
       		//Merge it with the array of existing galeries id
       		if(count($album->gallery_ids) > 0)
       			$sort = array_merge((array)$album->gallery_ids, $new);
       		else
       			$sort = $new;
   
       		//serialize it
       		$serialized = serialize($sort);
   
       		//Update the album
       		$wpdb->query("UPDATE $wpdb->nggalbum SET sortorder = '$serialized' WHERE id = $album->id ");
       	}
   
       	//BEGIN DEBUG
       	$debug = '[author : '.$gallery->author.'] [album id : '.$album->id.'] [serialized : '.$serialized.']';
       	nggGallery::show_message($debug);
       	//END DEBUG
   
       }
       ```
   
 * Therefore, every time a user with an assigned album will create a gallery it 
   will be automatically added to its album and displayed on the page with the album
   shortcode (eg : [album id=1 template=compact]).
 * Hope it will help,
 * HnB

Viewing 1 replies (of 1 total)

The topic ‘Display a user's gallery’ 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/)

## Tags

 * [display](https://wordpress.org/support/topic-tag/display/)
 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [nextgen](https://wordpress.org/support/topic-tag/nextgen/)
 * [role](https://wordpress.org/support/topic-tag/role/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [user](https://wordpress.org/support/topic-tag/user/)

 * 1 reply
 * 1 participant
 * Last reply from: [hnb](https://wordpress.org/support/users/hnb/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/display-a-users-gallery/#post-3349515)
 * Status: resolved