$author_slug, 'fields' => array( 'description' => true, 'active_installs' => true, 'rating' => true, 'num_ratings' => true, 'screenshot_url' => true, ), ); $response = themes_api( 'query_themes', $api_args ); $themes = array(); if ( ! is_wp_error( $response ) && isset( $response->themes ) ) { $themes = $response->themes; } // Sort by rating (highest first), then by active installs descending usort( $themes, function ( $a, $b ) { $a = (array) $a; $b = (array) $b; $a_rating = isset($a['rating']) ? (int) $a['rating'] : 0; $b_rating = isset($b['rating']) ? (int) $b['rating'] : 0; if ($a_rating == $b_rating) { $a_installs = isset($a['active_installs']) ? (int) $a['active_installs'] : 0; $b_installs = isset($b['active_installs']) ? (int) $b['active_installs'] : 0; return $b_installs - $a_installs; } return $b_rating - $a_rating; } ); ?>