Last active
August 29, 2015 14:09
-
-
Save ibrokemywp/2b1cfd0515076e631eaf to your computer and use it in GitHub Desktop.
Sort your custom post type via pre_get_posts like this
This file contains 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
/** | |
* Check before sorting your custom post type admin lists so you don't | |
* override other changes. | |
*/ | |
add_action( 'pre_get_posts', array( $this, 'admin_order_posts' ) ); | |
public function admin_order_posts( $query ) { | |
if( ( is_admin() && $query->is_admin ) && $query->get( 'post_type' ) == 'my_custom_post_type' ) { | |
// This prevents other orderby options from breaking. | |
if ( !$query->get( 'orderby' ) ) { | |
$query->set( 'orderby', 'menu_order' ); | |
$query->set( 'order', 'ASC' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment