Skip to content

Instantly share code, notes, and snippets.

@mindctrl
Last active June 24, 2017 13:55
Show Gist options
  • Save mindctrl/eceee8dd6f24f3c8dfee to your computer and use it in GitHub Desktop.
Save mindctrl/eceee8dd6f24f3c8dfee to your computer and use it in GitHub Desktop.
Sort the downloads archive in Easy Digital Downloads by number of sales
<?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' );
@rahilwazir
Copy link

Thanks!

@ozthegreat
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment