以下是一种可能的解决方案,但需要进行一些测试以确认其可行性。仅在以下情况下运行menu_order == 0
如果不是保存的自动草稿或修订
add_action( \'save_post\', \'incremental_save_wpse_113767\', 10, 2 );
function incremental_save_wpse_113767( $post_id, $post_object )
{
if( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
if( defined( \'DOING_AJAX\' ) && DOING_AJAX )
return;
# Block auto-drafts and revisions
# http://codex.wordpress.org/Post_Status_Transitions
if( in_array( $post_object->post_status, array( \'auto-draft\', \'inherit\' ) ) )
return;
# Menu order already set, do nothing
if( 0 != $post_object->menu_order )
return;
$menu_order = get_option( \'my_menu_order\' );
if( !$menu_order)
$menu_order = 5; // <-- Adjust to the desired initial value
$post_object->menu_order = $menu_order;
remove_action( \'save_post\', \'incremental_save_wpse_113767\' );
wp_update_post( $post_object );
add_action( \'save_post\', \'incremental_save_wpse_113767\', 10, 2 );
$menu_order += 5;
update_option( \'my_menu_order\', $menu_order );
}