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.
3
Answers
OK Guys,
Eventually, I have found a way to implement this feature. Here is what I have done.
This will create a new custom menu and will redirect at the page where I want.
Thanks all for your support and guidance.
if you have already made the first post:
in your
register_post_type
add these parameters:this will disable adding new posts to the post type.
And then the function to redirect the edit.php – making sure you pass the correct ID
One way of doing it will be to redirect on admin_init hook. Check if
$_GET[post_type']
is set and equal to your custom post type and the$pagenow
global isedit.php
, Then simply redirect it using wp_redirect().I would prefer the way to create a new custom menu and redirect it to the page needed.