I have created a custom post type called "Home Page" using register_post_type
and below is my code.
$labels = array(
'name' => __( 'Home Page'),
'singular_name' => __( 'Home Page'),
'edit_item' => __( 'Edit Home Page'),
);
$args = array(
'label' => __( 'Home Page'),
'description' => __( 'Custom Post Type'),
'labels' => $labels,
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'map_meta_cap' => fa,
'capabilities' => array(
'create_posts' => 'do_not_allow',
'delete_published_posts' => false,
'read_post' => false,
),
);
register_post_type( 'homepage', $args );
And I have used "Advanced Custom Fields" WordPress plugin to add custom fields to this new custom post type. These all working fine and its showing like below.
But the thing I want is, I will only have 1 record so if I click on "Home Page" on the left side bar admin menu link, it should be redirected to that particular record with something like post.php?post=37&action=edit
in the URL.
I already know doing 'show_in_menu' => false,
will hide the url from the left sidebar.
But how can I hide this menu and directly go to edit page for only single record which I will always have?
Can someone guide me what should I do from here on to achieve this?
Thanks in advance.
OK Guys,
Eventually, I have found a way to implement this feature. Here is what I have done.
// Adding custom menu for custom post type
function add_link_to_category_tips_n_tricks() {
$link = 'post.php?post=39&action=edit';
add_menu_page( 'Home Page', 'Home Page', 'edit_pages', $link, '', 'dashicons-admin-home', 8 );
}
add_action( 'admin_menu', 'add_link_to_category_tips_n_tricks' );
This will create a new custom menu and will redirect at the page where I want.
Thanks all for your support and guidance.