How To Create Custom Post Types By Using Wordpress Plugin
we want to create custom post type plugin in wordpress. once installed this plugin you are able to create/edit/delete in admin dashboard.
Step 1: First We need to create a custom-post-types folder in `wp-content/plugins/` .
Step 2: Create custom-post-types.php file with the following php code in `wp-content/plugins/custom-post-types/ folder`. The following code is for your plugin details
Step 3: Please copy and paste in your custom-post-types.php for registering a custom post type in wordpress.
Step 1: First We need to create a custom-post-types folder in `wp-content/plugins/` .
Step 2: Create custom-post-types.php file with the following php code in `wp-content/plugins/custom-post-types/ folder`. The following code is for your plugin details
Step 3: Please copy and paste in your custom-post-types.php for registering a custom post type in wordpress.
add_action( 'init', 'custom_post_types_init' );
functioncustom_post_types_init() {
$labels = array(
'name' => _x( 'Books', 'post type general name', 'custom-post-types' ),
'singular_name' => _x( 'Book', 'post type singular name', 'custom-post-types' ),
'menu_name' => _x( 'Books', 'admin menu', 'custom-post-types' ),
'name_admin_bar' => _x( 'Book', 'add new on admin bar', 'custom-post-types' ),
'add_new' => _x( 'Add New', 'book', 'custom-post-types' ),
'add_new_item' => __( 'Add New Book', 'custom-post-types' ),
'new_item' => __( 'New Book', 'custom-post-types' ),
'edit_item' => __( 'Edit Book', 'custom-post-types' ),
'view_item' => __( 'View Book', 'custom-post-types' ),
'all_items' => __( 'All Books', 'custom-post-types' ),
'search_items' => __( 'Search Books', 'custom-post-types' ),
'parent_item_colon' => __( 'Parent Books:', 'custom-post-types' ),
'not_found' => __( 'No books found.', 'custom-post-types' ),
'not_found_in_trash' => __( 'No books found in Trash.', 'custom-post-types' )
);
$args = array(
'labels' => $labels,
'description' => __( 'Description.', 'custom-post-types' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'book' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type( 'book', $args );
}
No comments: