# meow-gallery/4.1.6/classes/orderby.php

Meow Gallery, version 4.1.6. 38 lines.

- Page: https://pluginprobe.com/plugins/meow-gallery/4.1.6/code/classes/orderby.php
- Raw: https://pluginprobe.com/plugins/meow-gallery/4.1.6/raw/classes/orderby.php
- Modified: 2020-08-21T02:47:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/meow-gallery/4.1.6/code/classes/orderby.php#L10-L20`.

```php
<?php

class Meow_MGL_OrderBy {

	public $admin = null;

	static function run( $images, $orderby = null, $order = 'asc' ) {
		$sqlOrderBy = '';

		// Check params
		if ( $orderby === 'ids' ) {
			$images = $order === 'asc' ? sort( $images ) : rsort( $images );
		}
		else if ( $orderby === 'title' ) {
			$sqlOrderBy = $order === 'asc' ? ' ORDER BY p.post_title ASC' : ' ORDER BY p.post_title DESC';
		}
		else if ( $orderby === 'date' ) {
			$sqlOrderBy = $order === 'asc' ? ' ORDER BY p.post_date ASC' : '  ORDER BY p.post_date DESC';
		}

		// Apply sort
		if ( !empty( $sqlOrderBy ) ) {
			global $wpdb;
			$wpIdsPlaceHolders = array_fill( 0, count( $images ), '%d' );
			$wpIdsPlaceHolders = implode( ', ', $wpIdsPlaceHolders );
			$query = $wpdb->prepare( "SELECT p.ID
				FROM $wpdb->posts p
				WHERE p.ID IN ($wpIdsPlaceHolders)" . $sqlOrderBy, $images );
			$images = $wpdb->get_col( $query );
			
		}
		return $images;
	}

}

?>

```
