Define menu_order on Creation of New Custom Post?

Hi @fxfuture:

I think what you are looking for is the wp_insert_post_data hook. You can add this code to the bottom of your theme’s functions.php file and/or you can add it to a plugin:

add_filter('wp_insert_post_data','my_wp_insert_post_data',10,2);
function my_wp_insert_post_data($data, $postarr) {
  $post_type="video";
  if ($data['post_type']==$post_type && get_post($postarr['ID'])->post_status=='draft') {
    global $wpdb;
    $data['menu_order'] = $wpdb->get_var("SELECT MAX(menu_order)+1 AS menu_order FROM {$wpdb->posts} WHERE post_type="{$post_type}"");
  }
  return $data;
}

Leave a Comment

error code: 523