I have a CPT that have menu_order enabled, how can I make the menu_order values unique so it won’t have duplicates

You can interfere with save_post action then change menu_order to post_ID:

add_action('save_post', function($post_id, $post, $update) {
    if ($post->menu_order === $post_id) {
        return $post_id;
    } else {
        global $wpdb;

        $q = "UPDATE $wpdb->posts SET menu_order=%d WHERE ID=%d";

        $wpdb->query( $wpdb->prepare($q, [$post_id, $post_id]) );

        return $post_id;
    }
}, 9, 3);

Leave a Comment