Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Situation:

I am developing my first Wordpress plugin with multiple admin pages. This plugin has a menu and some submenus in Admin Menu. I am using Wordpress 3.9 on XAMPP, Windows 8.1 Pro.

Problem:

What I want to achieve is like Add New button (link) which is in All Posts page. I mean when one clicks on the Add New link in All Posts page, they are taken to the Add New page itself, with the submenu Add New selected.

enter image description here

Here is my code:

function nes_general_settings_view () { 
    echo "In General Settings";
}

function nes_vendor_view () { 
    ?>
    All Vendors <a href="<?=HOW_TO_LINK_TO_nes_vendor_new_view_function?>">Add New Vendor</a>
    <table>
       ...
    </table>
    <?php

}

function nes_vendor_new_view () { 
    echo "In New Vendor";
}

function nes_tell_us_view () {
    echo "In Tell Us";
}


add_action("admin_menu", function () {
add_menu_page(
    "Our Service",   
    "Our Service",           
    "manage_options",            
    "nes_general_settings",      
    "nes_general_settings_view", 
    null,                        
    4                            
);

add_submenu_page( "nes_general_settings", "General Settings", "General Settings", 0, "nes_general_settings", "nes_general_settings_view");

add_submenu_page( "nes_general_settings", "Vendors", "Vendors", 0, "nes_vendor", "nes_vendor_view");
add_submenu_page( "nes_general_settings", "New Vendor", "New Vendor", 0, "nes_vendor_new", "nes_vendor_new_view");

add_submenu_page( "nes_general_settings", "Tell Us", "Tell Us!", 0, "nes_tell_us", "nes_tell_us_view");

});

Question:

How to generate such a link (in particular HOW_TO_LINK_TO_nes_vendor_new_view_function in source code)? Shall I use a special function to generate dynamic contents? And also can you tell me which file generates the All Posts admin page, for the sake of reference?

share|improve this question
    
If you've created a CPT this should be automatic. If you are doing something other than that this question is both too broad and too poorly described to answer. –  s_ha_dum May 4 at 15:28
    
Can you add your code that you are using to add the submenu page you would like to link to? –  Douglas.Sesar May 4 at 15:28
    
@Douglas.Sesar: I updated added the source codes and gave more explaination. –  Musa May 5 at 4:45
    
@s_ha_dum Can you tell me what does CPT mean? Also I added more explaination to question. –  Musa May 5 at 4:50
    
CPT is Custom Post Type –  Douglas.Sesar May 5 at 12:30

1 Answer 1

up vote 0 down vote accepted

If I understand correctly what you are asking, you need the $menu_slug used when adding your menu pages:

//add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
//add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );

$your_link_url = admin_url( 'admin.php?page='.$menu_slug, 'http' );

OR SPECIFICALLY FOR YOU

$your_link_url = admin_url( 'admin.php?page=nes_vendor_new', 'http' );

You can always verify the link by clicking on the menu item and see where it takes you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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