Skip to content

Instantly share code, notes, and snippets.

@grantalltodavid
Created July 20, 2018 09:53
Show Gist options
  • Save grantalltodavid/50d2e0d14b4227badf6a22586f4e8233 to your computer and use it in GitHub Desktop.
Save grantalltodavid/50d2e0d14b4227badf6a22586f4e8233 to your computer and use it in GitHub Desktop.
Sliced Invoices - change default ordering of quotes/invoices in admin list view
// this will set default order by invoice/quote number
if ( is_admin() ) {
add_action( 'pre_get_posts', 'sliced_set_default_orderby', 11 );
}
function sliced_set_default_orderby( $query ) {
// double check to avoid interfering with any ajax requests
if ( ! sliced_get_the_type() ) {
return;
}
if ( ! isset( $_GET['order'] ) ) {
$query->set('order','DESC');
}
if ( ! isset( $_GET['orderby'] ) ) {
$query->set( 'meta_key', '_sliced_'.sliced_get_the_type().'_number' );
$query->set( 'orderby', 'meta_value_num' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment