Last active
June 24, 2017 13:55
-
-
Save mindctrl/eceee8dd6f24f3c8dfee to your computer and use it in GitHub Desktop.
Sort the downloads archive in Easy Digital Downloads by number of sales
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Easy Digital Downloads - Sort archive by number of sales | |
*/ | |
function jp_sort_downloads_archive( $query ) { | |
if ( is_post_type_archive( 'download' ) && $query->is_main_query() ) { | |
$query->set( 'meta_key', '_edd_download_sales' ); | |
$query->set( 'orderby', 'meta_value_num' ); | |
$query->set( 'order', 'DESC' ); | |
} | |
} | |
add_action( 'pre_get_posts', 'jp_sort_downloads_archive' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!