How do I make a custom taxonomy for a CPT appear inbetween title and editor boxes?

This may be a duplicate of this question – Changing the priority of a custom taxonomy’s metabox but I can’t work out how to apply that answer. I’m unsure what my custom taxonomy div label would be and how to get it to apply to only a custom post type.

I have a custom taxonomy, created with register_taxonomy and I would like to make the taxonomy box appear inbetween the post title field and the editor field in the wp-admin add/edit post area, for a set custom post type. Usually you can change CPT order in the admin menus with a priority field, but I don’t think there is one for taxonomies…

Read More

Thanks

Related posts

Leave a Reply

2 comments

  1. In your case you can edit the following code to accomplish what you are looking for by assigning the custom taxonomy meta box to a custom context and then running do_meta_boxes

    /**
     * insert meta boxes before main editor below title
     */
    function wpse_140900_add_meta_boxes_after_title( $post ){
    
        // per the comment below filter by post type
        // http://wordpress.stackexchange.com/questions/140900/how-do-i-make-a-custom-taxonomy-for-a-cpt-appear-inbetween-title-and-editor-boxe/140906#comment201984_140906
        if( $post->post_type != 'targeted-post-type' )
            return;
    
        // setup function vars
        global $wp_meta_boxes;
        $current_screen = get_current_screen();
        $registered_taxonomy = 'custom_taxonomy';
    
        // move meta box to after_title position
        $wp_meta_boxes[$current_screen->id]['after_title']['core'][ $registered_taxonomy . 'div'] = $wp_meta_boxes[$current_screen->id]['side']['core'][ $registered_taxonomy . 'div' ];
    
        // display registered meta boxes for after_title
        do_meta_boxes( get_current_screen(), 'after_title', $post );
    
        // remove meta box from displaying in the "default"
        unset( $wp_meta_boxes[$current_screen->id]['side']['core'][ $registered_taxonomy . 'div' ] );
    }
    
    // init meta boxes after title
    add_action( 'edit_form_after_title', 'wpse_140900_add_meta_boxes_after_title' );
    

    In this particular code snippet it will move your sidebar meta boxes below the title and above the content editor fields.

  2. After researching s_ha_dum’s link and others for a while it seemed like the only way to position meta boxes in between the title and editor fields was to remove and readd the main editor like this, but this feels a bit hacky to me and receives a warning from another answerer about potential problems.

    I was able to combine @s_ha_dum’s method for creating a position for a new meta box, and this code which enabled me to create a new meta box that functions like a category taxonomy.

    In case it helps anyone, here is the working code to make a custom taxonomy appear in-between the title and editor:

    /***************************************************************
    * Function create_ideas_type
    * Register ideas type taxonomy 
    ***************************************************************/
    add_action( 'init', 'create_ideas_type', 0 );
    
    function create_ideas_type() {
    
    $labels = array(
        'name' => __( 'Type'),
        'singular_name' => __( 'Type'),
        'search_items' =>  __( 'Search Types' ),
        'popular_items' => __( 'Popular Types' ),
        'all_items' => __( 'All Types' ),
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __( 'Edit Type' ),
        'update_item' => __( 'Update Type' ),
        'add_new_item' => __( 'Add New Type' ),
        'new_item_name' => __( 'New Type Name' ),
        'separate_items_with_commas' => __( 'Separate types with commas' ),
        'add_or_remove_items' => __( 'Add or remove types' ),
        'choose_from_most_used' => __( 'Choose from the most used types' ),
    );
    
    register_taxonomy('ideas_type','ideas', array(
        'label' => __('Type'),
        'labels' => $labels,
        'public' => true,
        'hierarchical' => true,
        'show_ui' => true,
        'show_in_nav_menus' => false,   
        'query_var' => true,
        'rewrite' => array( 'slug' => 'greenhouse/ideas-ambitions/type', 'with_front' => false),
        ));
    }
    /***************************************************************
    * Functions add_before_editor and move_ideaspost_box
    * Reorder the metabox to appear in between title and editor
    ***************************************************************/ 
    // use the action to create a place for your meta box
    add_action('edit_form_after_title','add_before_editor');
    
    function add_before_editor($post) {
        global $post;
        do_meta_boxes('ideas', 'pre_editor', $post);
    }
    
    add_action('do_meta_boxes', 'move_ideaspost_box');
    
    function move_ideaspost_box() {
    
        global $post;
        if( $post->post_type != 'ideas' )
            return;
    
        remove_meta_box( 'ideas_typediv', 'ideas', 'side' );
        $t_name = 'ideas_type';
        if ( !is_taxonomy_hierarchical($t_name) )
            add_meta_box('tagsdiv-' . $t_name, "Type", 'post_tags_meta_box', 'ideas', 'pre_editor', 'low', array( 'taxonomy' => $t_name ));
        else
            add_meta_box($t_name . 'div', "Type", 'post_categories_meta_box', 'ideas', 'pre_editor', 'low', array( 'taxonomy' => $t_name ));
    }