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?