1

I want to provide functionality to create a single post into my custom post type. And for this, when user click on main option (name of post) at left side bar in word-press back-end It's automatically redirect on "Add New Post" or if a post already created then automatically redirect on "Edit Post" (existing post edit).

Right now at back-end the post option look like this -

My Posts

So, now i don't want sub menu. and preform add/edit post option on main menu click. Is this possible, if yes then can you please tell me how to achieve this?

0

2 Answers 2

0

I get a way to override this problem. by using "add_action" I can able to achieve my goal.

  add_action("load-edit.php", 'block_listing_page');
  //-- Block user to access post listing page    
  function block_listing_page() {
        if ($_GET["post_type"] == "your_custom_post_type") {
            $args = array('post_type' => 'your_custom_post_type', 'post_status' => 'publish');
            $galleryPosts = get_posts($args);
            if (!empty($galleryPosts) && count($galleryPosts) > 0) {
                wp_redirect("post.php?post=" . $galleryPosts[0]->ID . "&action=edit");
            } else {
                wp_redirect("post-new.php?post_type=your_custom_post_type");
            }
        }
    }

    add_action("load-post-new.php", 'block_create_multiple_gallery');
    //-- Check if a post is exist open in edit mode when clicking add new post
    function block_create_multiple_gallery() {
        if ($_GET["post_type"] == "your_custom_post_type") {
            $args = array('post_type' => 'your_custom_post_type', 'post_status' => 'publish');
            $galleryPosts = get_posts($args);
            if (!empty($galleryPosts) && count($galleryPosts) > 0) {
                wp_redirect("post.php?post=" . $galleryPosts[0]->ID . "&action=edit");
            } else {
                return true;
            }
        }
    }

But, still i want to hide sub menu (i.e "Add New"); Can anyone help me to get this done?

0

You need to use the right hooks (which are not always the same as the URLs/slugs), and it doesn't hurt to use a hook that runs later (e.g., admin_init):

add_action( 'admin_init', 'wpaws_136058_remove_menu_pages' );

function wpaws_136058_remove_menu_pages() {



    /*You can check list of menu item by below code:
    foreach ($GLOBALS['menu'] as $key => $value) {          
        print('<pre');
        print_r($value);
        print('</pre>');
    }
    */

    //Remove item from menu
    remove_menu_page('menu_to_remove');

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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