Create custom post type in plugin code. Invalid post type page and next…puf
-
Hi all,
I’ve trying to create a custom post type in my plugin code, but when I’ve activate my plugin the new post type appear in the admin menu and when I click on it I see a “Invalid post type” page and, when I come back to admin interface, the link to my new custom post type is disappear.
My code is:
... add_action( 'init', array( $class_instance, 'to_custom_page' )); ...“Class instance” method called by do_action is:
public function to_custom_page(){ //create page for plugin $post_id= get_option($this->page_id, -1); if($post_id == -1){ //register post type to hide page /*$res= register_post_type( 'carriergem_page', array( 'label' => __( 'CGL Pages' ), 'public' => true, ) );*/ $res = register_post_type('carriergem_cpt', array( 'labels' => array( 'name' => 'CGL Pagine', 'singular_name' => 'CGL Pagina', 'add_new' => 'Aggiungi nuova', 'add_new_item' => 'Aggiungi nuova pagina', 'edit_item' => 'Modifica pagina', 'new_item' => 'Nuova pagina', 'view_item' => 'Visualizza pagina', 'search_items' => 'Cerca pagine', 'not_found' => 'Nessun pagina trovata.', 'not_found_in_trash' => 'Nessuna pagina presente nel cestino.', 'parent_item_colon' => 'Pagina genitore:', 'all_items' => 'Tutte le pagine', 'archives' => 'Archivi pagine', 'insert_into_item' => 'Inserisci nella pagina', 'uploaded_to_this_item' => 'Caricato in questa pagina', 'featured_image' => 'Immagine in evidenza', 'set_featured_image' => 'Imposta l\'immagine in evidenza', 'remove_featured_image' => 'Rimuovi immagine in evidenza', 'use_featured_image' => 'Utilizza come immagine in evidenza', 'filter_items_list' => 'Filtra elenco pagine', 'items_list_navigation' => 'Navigazione elenco pagine', 'items_list' => 'Elenco delle pagine', 'menu_name' => 'CGL Pagine', 'name_admin_bar' => 'CGL Pagina', ), 'description' => '', 'public' => true, 'hierarchical' => true, 'exclude_from_search' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 21, 'capability_type' => array('page','pages'), 'map_meta_cap' => true, 'taxonomies' => array ( ), 'can_export' => true, 'delete_with_user' => true, //'_builtin' => true, //'name' => 'cgl_cpt', 'label' => 'CGL Pagine', ) ); //register page $post = array( 'comment_status' => 'closed', 'ping_status' => 'closed' , 'post_author' => 1, 'post_date' => date('Y-m-d H:i:s'), 'post_name' => 'plugin-post', 'post_status' => 'publish' , 'post_title' => '', 'post_type' => 'carriergem_cpt',//'page', ); $post_id= wp_insert_post( $post ); add_option($this->page_id, $post_id); } add_rewrite_rule(..., 'top'); flush_rewrite_rules(); }I’ve Magic Filed plugin active. This plugin do the same thing in the simple way but I need to create my custom post type by my plugin code. Can Magic Field have a role in this issue?
I’m not english and my english is really bad. Please be patience š .
The topic ‘Create custom post type in plugin code. Invalid post type page and next…puf’ is closed to new replies.