Title: sort order in a function
Last modified: August 19, 2016

---

# sort order in a function

 *  [Damien](https://wordpress.org/support/users/takster/)
 * (@takster)
 * [16 years ago](https://wordpress.org/support/topic/sort-order-in-a-function/)
 * Hi, I have a function that shows the most liked posts with the like count, displayed
   highest to lowest in the admin, but I cant for the life of me get the sort order
   ASC or DESC to work. Can anyone see any obvious error in the sql?
 * Thanks in advance 🙂
 * table: wp_likes_count
    row: like_pid (page ID) row: like_count (likes per page/
   article)
 *     ```
       function like_get_top( $limit = 5 ) {
       	global $wpdb;
           $top = $wpdb->get_results( $wpdb->prepare (
           "SELECT like_pid FROM " . $wpdb->prefix . "likes_count ORDER BY like_count DESC LIMIT %d",
           $limit
       	), ARRAY_N );
       	$top = array_map('_like_flatten_array', $top);
           return apply_filters('like_get_top', get_posts( array('post__in' => $top) ));
       }
   
       function like_get_bottom( $limit = 5 ) {
       	global $wpdb;
   
       	$bottom = $wpdb->get_results( $wpdb->prepare (
       		"SELECT like_pid FROM " . $wpdb->prefix . "likes_count ORDER BY like_count ASC LIMIT %d",
       		$limit
       	), ARRAY_N );
       	$bottom = array_map('_like_flatten_array', $bottom);
   
       	return apply_filters('like_get_bottom', get_posts( array('post__in' => $bottom) ));
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [Damien](https://wordpress.org/support/users/takster/)
 * (@takster)
 * [16 years ago](https://wordpress.org/support/topic/sort-order-in-a-function/#post-1493570)
 * `"SELECT like_count FROM" . $wpdb->prefix . "likes_count ORDER BY like_count 
   ASC LIMIT %d",`
 * works in phpmyadmin exactly as planned but breaks in wordpress, shows blank. :/

Viewing 1 replies (of 1 total)

The topic ‘sort order in a function’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Damien](https://wordpress.org/support/users/takster/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/sort-order-in-a-function/#post-1493570)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
