Support » Fixing WordPress » Add default menu_order value

  • Hi
    I want to be able to add a menu_order value=1 to every custom post_type I create, is it possible? Don’t know, by creating a filter or something like that…

    I have a post_type = products, I want to set menu_order = 1 to all new posts under this post_type

Viewing 2 replies - 1 through 2 (of 2 total)
  • Drew Jaynes


    WordPress Core Developer

    Are you manually creating the custom post types in the functions file, or using a plugin to create them? Either way, you should be able to set the menu_position parameter described in detail on the register_post_type Codex page.

    Chris Olbekson


    Level 12 Bug Squasher & Forum Moderator

    Here is a filter I wrote to set the menu order on new posts. This sets it to 8 but you can change where it states +8 to +1.

    `add_filter( ‘wp_insert_post_data’, ‘my_wp_insert_post_data’, 10, 2 );
    function my_wp_insert_post_data( $data, $postarr ) {
    global $post;
    $post_type= get_post_type( $post );
    if ( $data[ ‘post_type’ ] == $post_type && get_post( $postarr[ ‘ID’ ] )->post_status == ‘draft’ ) {
    global $wpdb;
    $data[ ‘menu_order’ ]=$wpdb->get_var( “SELECT MIN(menu_order)+8 AS menu_order FROM {$wpdb->posts} WHERE post_type='{$post_type}'” );
    return $data;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add default menu_order value’ is closed to new replies.