• 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

    (@takster)

    "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.