Created
July 20, 2018 09:53
-
-
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 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
// 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