Sometimes the easiest things cause the most problems! This is a case:
I’ve spend 4 hours yesterday trying to solve this problem but couldn’t. I am sure I have something missing! Help is appreciated
So I’ve wrote a piece of code that would automatically creates a page. The problem arises when i give this page a custom post type: The page doesn’t show in pages area or when visited.
I’ve made sure that the post type is all lowercase letters. I also verified that the post type is successfully registered.
The insert post runs successfully and no errors are shown in debugging mode!
Am I missing something? I went crazy on this.
Code that creates post type:
add_action( 'init', 'create_whatever' );
function create_whatever() {
register_post_type( 'whatever',
array(
'labels' => array( 'name' => 'Whatever Page', 'singular_name' => 'Whatever Page' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => false,
'query_var' => true,
'has_archive' => false
)
);
}
Code uses to create post:
//not all pages have same array, this is a flexible way to populate it.
$_p = array();
$_p['post_title'] = $this->whatever_title;
$_p['post_content'] = $this->whatever_desc;
$_p['post_status'] = 'publish';
$_p['post_type'] = 'whatever';
$_p['comment_status'] = 'closed';
$_p['ping_status'] = 'closed';
$_p['post_category'] = array(1);
$page_id = wp_insert_post( $_p );
When post_type is page, everything goes as expected but when i change it to the custom post type. The page doesn't show up.
Please note that the first code is called before the second. I also tried adding the first code to my themes function rather than the plugin. Same stuff.
Am I missing something so vital here?
Custom Post type will be used just to identify the page and redirect it to a special page template.
I was able to achieve the same effect without page types (I used page id, because I will need this for only one page), the problem here was that the page will apear in the menu and i dont want it to do so. Yes I know we can remove it, but i want a complete solution?
Thanks!