我有办法解决这个问题。通过使用“add\\u action”,我可以实现我的目标。
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;
}
}
}
但是,
still i want to hide sub menu (i.e "Add New"); Can anyone help me to get this done?