0

I'm using CPTUI to create taxonomies and categories for Facet-WP, which i'm using to sort and filter products on the pages i'm creating. This is the problem i'm facing :-

enter image description here

As you can see, the Custom post types on the left have completely overwhelmed the section on the left (Inductive_proximities). Is there a way to put these into some custom page or dropdown, so as to avoid cluttering this page? I have to create about a 100 more of these and i'm dreading the mess this will create.

Thanks

0

There are multiple ways to remove or re-order these. I've created couple of post types (Test1, Test2, Test3) to test following ways.

enter image description here

CPT UI configuration way

You can add new post types with Settings > Show in menu set to False and the post type will not appear in menu at all.

enter image description here

Plugin way

You might want to try plugin such as Admin Menu Editor (https://wordpress.org/plugins/admin-menu-editor/) in combination with previous setting, that will let drag and drop edit your menu and add the links to the post types that don't show in menu.

enter image description here

Manual code way

You can achieve same results as above by hardcoding this into custom plugin or your theme's functions.php for example. The manual way would filter register_post_type_args hook.

function wp332896_custom_post_type_args( $args, $post_type ) {
    $post_types_to_not_show_in_menu = ['test1', 'test2', 'test3'];
    if ( in_array($post_type, $post_types_to_not_show_in_menu) ) {
        $args['show_in_menu'] = false;
    }

    return $args;
}
add_filter( 'register_post_type_args', 'wp332896_custom_post_type_args', 20, 2 );

Note that this is basically the same as using CPT UI configuration to change Show in menu value to false, just wrote to code. Variable $post_types_to_not_show_in_menu holds array of post types that are not to be shown in menu.

Dynamic code way

If you wanted to do this for all the post types registered with CPT UI, we could use CPT UI's function cptui_get_post_type_data().

function wp332896_custom_post_type_args( $args, $post_type ) {

    $post_types_to_not_show_in_menu = [];

    if (function_exists('cptui_get_post_type_data')) {
        $post_types_to_not_show_in_menu = array_column(cptui_get_post_type_data(), 'name');
    }

    if ( in_array($post_type, $post_types_to_not_show_in_menu) ) {
        $args['show_in_menu'] = false;
    }

    return $args;
}
add_filter( 'register_post_type_args', 'wp332896_custom_post_type_args', 20, 2 );

Note that $post_types_to_not_show_in_menu now uses that function to get all names of post types registered with CPT UI.

To finish it, you can add "folder" with these post types as submenu. I'll connect the folder and the submenu pages by using string "cptfolder", but you can have just about any.

function wp332896_folder_menu() {

    $menu_slug = 'cptfolder';

    add_menu_page('Folder', 'Folder', 'manage_options', $menu_slug);

    $cpt_post_types = [];

    if (function_exists('cptui_get_post_type_data')) {
        $cpt_post_types = cptui_get_post_type_data();
    }

    foreach($cpt_post_types as $post_type) {
        add_submenu_page($menu_slug, $post_type['label'], $post_type['label'], 'manage_options', 'edit.php?post_type='.$post_type['name']);
    }
 }

add_action('admin_menu', 'wp332896_folder_menu');

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.