admin(edit.php)中的Post列表使用普通WP_Query
, 就像前端可以使用pre_get_posts
.
add_action(\'pre_get_posts\', \'reorder_my_cpt\');
function reorder_my_cpt( $q ) {
if ( !is_admin() || !$q->is_main_query() ) {
return;
}
$s = get_current_screen();
// change \'book\' with your real CPT name
if ( $s->base === \'edit\' && $s->post_type === \'book\' ) {
$q->set(\'orderby\', \'menu_order\');
$q->set(\'order\', \'ASC\');
}
}