Plugin development for custom post type
-
Hi,
I am try to develop a plugin for create post type but the register post type is not working can any one help me.
add_action('init','newposttype_create'); function newposttype_create() { $newpost="mysliderservice"; $labels = array( 'name' => _x( $newpost, 'Post type general name', 'textdomain' ), 'singular_name' => _x( $newpost, 'Post type singular name', 'textdomain' ), 'menu_name' => _x( 's', 'Admin Menu text', 'textdomain' ), 'name_admin_bar' => _x( $newpost, 'Add New on Toolbar', 'textdomain' ), 'add_new' => __( 'Add New', 'textdomain' ), 'add_new_item' => __( 'Add New ', 'textdomain' ), 'new_item' => __( 'New ', 'textdomain' ), 'edit_item' => __( 'Edit ', 'textdomain' ), 'view_item' => __( 'View ', 'textdomain' ), 'all_items' => __( 'All ', 'textdomain' ), 'search_items' => __( 'Search ', 'textdomain' ), 'parent_item_colon' => __( 'Parent :', 'textdomain' ), 'not_found' => __( 'No found.', 'textdomain' ), 'not_found_in_trash' => __( 'No found in Trash.', 'textdomain' ), 'featured_image' => _x( ' Cover Image', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'textdomain' ), 'set_featured_image' => _x( 'Set cover image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'textdomain' ), 'remove_featured_image' => _x( 'Remove cover image', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'textdomain' ), 'use_featured_image' => _x( 'Use as cover image', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'textdomain' ), 'archives' => _x( ' archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'textdomain' ), 'insert_into_item' => _x( 'Insert into Location', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'textdomain' ), 'uploaded_to_this_item' => _x( 'Uploaded to this Location', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'textdomain' ), 'filter_items_list' => _x( 'Filter Locations list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'textdomain' ), 'items_list_navigation' => _x( ' list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'textdomain' ), 'items_list' => _x( ' list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'textdomain' ), ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array( 'slug' => $newpost ), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt'), ); register_post_type( $newpost, $args ); } function handle_form() { if( ! isset( $_POST['awesome_form'] ) || ! wp_verify_nonce( $_POST['awesome_form'], 'awesome_update' ) ){ ?> <div class="error"> <p>Sorry, your nonce was not correct. Please try again.</p> </div> <?php exit; } else { $firstpost = sanitize_text_field($_POST['fposttype'] ); $secondpost = sanitize_text_field($_POST['sposttype'] ); $newpost=$firstpost.$secondpost; echo $newpost; add_action('init','newposttype_create'); } } <form method="POST" action=""> <input type="hidden" name="updated" value="true" /> <?php wp_nonce_field( 'awesome_update', 'awesome_form' ); ?> <table class="form-table"> <tbody> <tr> <th><label for="fposttype">Select Post Type</label></th> <td> <select name="fposttype" id="fposttype"/> <?php $args = array( 'public' => true, '_builtin' => false ); $output = 'names'; // 'names' or 'objects' (default: 'names') $operator = 'and'; // 'and' or 'or' (default: 'and') $post_types = get_post_types( $args, $output, $operator ); if ( $post_types ) { foreach ( $post_types as $post_type ){ ?> <option value="<?=$post_type?>" onchange="javascript:changesecondpslop(this.value);"><?=$post_type?></option> <?php } } ?> </select> </td> </tr> <tr> <th><label for="sposttype">Select Post Type</label></th> <td> <select name="sposttype" id="sposttype"/> <option>Select One</option> </select> </td> </tr> <tr> <th><label for="seltmp">Select Template</label></th> <td> <select name="seltmp" id="seltmp"/> <option>Select One</option> <?php $default = ''; $post_type = 'page'; $templates = get_page_templates( null, $post_type ); ksort( $templates ); foreach ( array_keys( $templates ) as $template ) { $selected = selected( $default, $templates[ $template ], false ); echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>'; } ?> </select> </td> </tr> </tbody> </table> <p class="submit"> <a>Submit</a> </p> <p class="submit"> <input type="submit" name="submit" id="submit" class="button button-primary" value="Check My Info!"> </p> </form>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Plugin development for custom post type’ is closed to new replies.