Title: Gallery Shortcode Orderby?
Last modified: August 19, 2016

---

# Gallery Shortcode Orderby?

 *  [kinglu](https://wordpress.org/support/users/kinglu/)
 * (@kinglu)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/gallery-shortcode-orderby/)
 * I use the Sandbox template frame for my WordPress, it’s function.php has override
   some default templates including Gallery shorcode. I have tried to modify “orderby”
   code to replace the thumbnails order. but it doesn’t work, whether “ID DESC”,”
   menu_order DESC”,or “ID ASC” etc. the thumbnails always listed as “5 4 3 2 1”,
   how do i replace them to “1 2 3 4 5”?
 * code below
 *     ```
       // Function to filter the default gallery shortcode
       function sandbox_gallery($attr) {
       	global $post;
       	if ( isset($attr['orderby']) ) {
       		$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
       		if ( !$attr['orderby'] )
       			unset($attr['orderby']);
       	}
   
       	extract(shortcode_atts( array(
       		'orderby'    => 'ID DESC',
       		'id'         => $post->ID,
       		'itemtag'    => 'li',
       		'icontag'    => 'div',
       		'captiontag' => 'span',
       		'columns'    => 99,
       		'size'       => 'thumbnail',
       	), $attr ));
   
       	$id           =  intval($id);
       	$orderby      =  addslashes($orderby);
       	$attachments  =  get_children("post_parent=$id&post_type=attachment&post_mime_type=image&orderby={$orderby}");
       ```
   

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

 *  Thread Starter [kinglu](https://wordpress.org/support/users/kinglu/)
 * (@kinglu)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/gallery-shortcode-orderby/#post-1198064)
 * Waiting for an answer!
 *  Thread Starter [kinglu](https://wordpress.org/support/users/kinglu/)
 * (@kinglu)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/gallery-shortcode-orderby/#post-1198135)
 * Waiting for an answer!

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

The topic ‘Gallery Shortcode Orderby?’ is closed to new replies.

## Tags

 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [orderby](https://wordpress.org/support/topic-tag/orderby/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [kinglu](https://wordpress.org/support/users/kinglu/)
 * Last activity: [16 years, 8 months ago](https://wordpress.org/support/topic/gallery-shortcode-orderby/#post-1198135)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
