How to Create Custom Post Type in WordPress
Post Types is a term used to refer to different types of content in a WordPress site. In all practical sense, it should be called content type. WordPress come with some default post type like page, post etc, but in some cases you may need to create custom post type according to your application need. Here are the simplest way to create a custom post type without using any plugin.
You need to register custom post type and it’s hook in your theme function.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
// Register Custom Post Type function custom_post_type() { $labels = array( 'name' => _x( 'Questions', 'Post Type General Name' ), 'singular_name' => _x( 'Question', 'Post Type Singular Name' ), 'menu_name' => __( 'Questions'), 'parent_item_colon' => __( 'Parent Item:'), 'all_items' => __( 'All Questions'), 'view_item' => __( 'View Questions'), 'add_new_item' => __( 'Add New Question'), 'add_new' => __( 'Add Question'), 'edit_item' => __( 'Edit Question'), 'update_item' => __( 'Update Question'), 'search_items' => __( 'Search Question'), 'not_found' => __( 'Not found'), 'not_found_in_trash' => __( 'Not found in Trash'), ); $args = array( 'label' => __( 'Questions'), 'description' => __( 'Questions Description'), 'labels' => $labels, 'supports' => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats'), 'taxonomies' => array( 'category', 'post_tag' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'menu_icon' => get_template_directory_uri().'/images/article.png', 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => true, 'publicly_queryable' => true, 'capability_type' => 'post', ); register_post_type( 'question', $args ); } // Hook into the 'init' action add_action( 'init', 'custom_post_type', 0 ); |
[paypal-donation]