WordPress Development Asked by Andrea Sciamanna on December 26, 2021
I’m writing a plugin that relies on custom post types, new taxonomy and few custom fields.
All this data will be private (not queryable or searchable).
I’d like to provide an admin page to the user, to add and edit this data in a more user-friendly way.
For instance, the custom post type will have only a title and the excerpt field, one taxonomy and the custom fields.
I know how to add meta boxes to a custom post type, but this is not enough to me.
I’d like to make a completely custom html interface that will take care of adding/saving/deleting the custom post type and handle the taxonomy and metas.
Just to be clear, I know already ho to write a normal plugin and handle plugin’s options.
I don’t know how, with this plugin I can:
There is some how-to out there that could help me achieve this?
Add menus and submenus like:
add_action('admin_menu', 'custom_plugin_menu');
function custom_plugin_menu() {
$page_title = 'Parent Menu Title';
$menu_title = 'Parent Menu Title';
$capability = 'manage_options';
$menu_slug = 'parent_menu_slug';
$function = 'whatever_for_main_page_function';
$icon_url = 'dashicons-admin-generic';
$position = 4;
add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);
$parent_slug = 'parent_menu_slug';
$page_title = 'Submenu Page Title';
$menu_title = 'Submenu Page Title';
$capability = 'manage_options';
$menu_slug = 'edit-tags.php?taxonomy=your_taxonomy_name&post_type=custom_post_type_name';
$function = null;
$position = null;
add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function, $position);
}
finally:
add_filter('parent_file', 'menu_highlight');
function menu_highlight($parent_file) {
global $plugin_page, $submenu_file, $post_type, $taxonomy;
if ('custom_post_type_name' == $post_type) {
if ($taxonomy == 'your_taxonomy_name') {
$plugin_page = 'edit-tags.php?taxonomy= your_taxonomy_name&post_type= custom_post_type_name'; // the submenu slug
$submenu_file = 'edit-tags.php?taxonomy= your_taxonomy_name&post_type= custom_post_type_name'; // the submenu slug
}
}
return $parent_file;
}
Hope I put all that in correctly. Nest any else if's inside the taxonomy check and add same for other post types.
Answered by Reinaldo Novoa on December 26, 2021
This is how it can be done:
add_action('admin_menu' , 'add_to_cpt_menu');
function add_to_cpt_menu() {
add_submenu_page('edit.php?post_type=name_of_post_type', 'Custom Post Type Admin', 'Custom Settings', 'edit_posts', basename(__FILE__), 'cpt_menu_function');
}
Answered by AlanP on December 26, 2021
You will need to start reading about the setting and options API, and then pull your CPT and Taxonomies into it.
Have a start here:
Class Reference/WP List Table « WordPress Codex
Administration Menus « WordPress Codex
Answered by Wyck on December 26, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP