Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Post Type and Custom Taxonomy as submenu of a plugin WordPress

  • SOLVED

I'm building a WP plugin whose options/settings are added to Dashboard as top-level menu page and a couple of sub-menu pages. No problem here at all. This plugin includes usage of Custom Post Types and Custom Taxonomy.

It's quite easy to add both CPT and CT to Dashboard under separate menu because more or less everything is done by WordPress.

However, what I want is the following:

My Plugin Menu Title
+----------> Custom Posts
+----------> Add New Custom Post
+----------> My Custom Taxonomy
+----------> * Plugin Settings Page


* please note that I know how to add plugin options/settings page!

I'm using a class to build plugin and all of sub-menu items MUST have a valid callback function. For example:

add_submenu_page('plugin-name-top-level-handle', __('Settings', $this->localizationDomain), __('Settings', $this->localizationDomain), 'manage_options', 'plugin-name-edit-options', array(&$this,'options_sublevel_page'));

...which means that "options_sublevel_page" is a callback function.

Answers (1)

2012-09-11

Arnav Joy answers:

you have only one CPT or want to lists all registered CPT of your site?


dameer comments:

One CPT and one CT defined in plugin code.


Arnav Joy comments:

few more questions:

1. do you want to list all these posts to your plugins page or want to redirect user to the default CTP list screen?

2. Do you want to redirect user to the default post add screen or want to add it on your own plugin's page?

3. name of your CPT?


dameer comments:

1. It doesn't really matter, I prefer simpler method which is (I guess) redirect to WP's default CPT screen

2. Default will be just fine

3. Custom Post Type name: SFP Post
Custom Taxonomy name: SFP Categories


Arnav Joy comments:

here are the three new menus

<?php
add_submenu_page('plugin-name-top-level-handle', __('Custom Posts', $this->localizationDomain), __('Custom Posts', $this->localizationDomain), 'manage_options', 'plugin-name-show-posta', array(&$this,'show_posts'));

add_submenu_page('plugin-name-top-level-handle', __('Add New Custom Post', $this->localizationDomain), __('Add New Custom Post', $this->localizationDomain), 'manage_options', 'plugin-name-add-post', array(&$this,'add_new_post'));

add_submenu_page('plugin-name-top-level-handle', __('My Custom Taxonomy', $this->localizationDomain), __('My Custom Taxonomy', $this->localizationDomain), 'manage_options', 'plugin-name-show-tax', array(&$this,'show_taxonomy'));
?>



and here is the function to redirect them to default screen..


<?php

function add_new_post(){
echo 'please wait while we are redirecting to desired screen......';
$post_type = 'SFP';
$url = admin_url().'/post-new.php?post_type='.$post_type;
?>
<script>location.href='<?php echo $url;?>';</script>
<?php

}

function show_posts(){
echo 'please wait while we are redirecting to desired screen......';
$post_type = 'SFP';
$url = admin_url().'/edit.php?post_type='.$post_type;
?>
<script>location.href='<?php echo $url;?>';</script>
<?php

}

function show_taxonomy(){
echo 'please wait while we are redirecting to desired screen......';
$post_type = 'SFP';
$post_tax = 'SFP ';
$url = admin_url().'/edit-tags.php?taxonomy='.$post_tax.'&post_type='.$post_type;
?>
<script>location.href='<?php echo $url;?>';</script>
<?php

}

?>


Arnav Joy comments:

please change the post type and taxonomy name as yours


$post_type = 'SFP';

$post_tax = 'SFP ';


dameer comments:

OK, lemme give it a try for a minute....


dameer comments:

YES! That should be it! I'll be glad if you allow me to contact you for any further cooperation. Thanks a bunch!


dameer comments:

How do I assign you a prize?!?


dameer comments:

Ahhh, never mind, I've figured it out. Stay well!