PluginProbe
Meow Gallery / 4.2.6
Meow Gallery v4.2.6
5.5.4 5.5.3 5.5.2 5.5.1 5.5.0 5.4.9 5.4.8 5.4.7 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 All 156 releases
meow-gallery / classes / orderby.php

orderby.php in Meow Gallery 4.2.6, at classes/orderby.php

38 lines 940 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Meow_MGL_OrderBy {
4
5 public $admin = null;
6
7 static function run( $images, $orderby = null, $order = 'asc' ) {
8 $sqlOrderBy = '';
9
10 // Check params
11 if ( $orderby === 'ids' ) {
12 $images = $order === 'asc' ? sort( $images ) : rsort( $images );
13 }
14 else if ( $orderby === 'title' ) {
15 $sqlOrderBy = $order === 'asc' ? ' ORDER BY p.post_title ASC' : ' ORDER BY p.post_title DESC';
16 }
17 else if ( $orderby === 'date' ) {
18 $sqlOrderBy = $order === 'asc' ? ' ORDER BY p.post_date ASC' : ' ORDER BY p.post_date DESC';
19 }
20
21 // Apply sort
22 if ( !empty( $sqlOrderBy ) ) {
23 global $wpdb;
24 $wpIdsPlaceHolders = array_fill( 0, count( $images ), '%d' );
25 $wpIdsPlaceHolders = implode( ', ', $wpIdsPlaceHolders );
26 $query = $wpdb->prepare( "SELECT p.ID
27 FROM $wpdb->posts p
28 WHERE p.ID IN ($wpIdsPlaceHolders)" . $sqlOrderBy, $images );
29 $images = $wpdb->get_col( $query );
30
31 }
32 return $images;
33 }
34
35 }
36
37 ?>
38