Tuesday, 9 January 2018

Create custom post type in wordpress.

Create custom post type in wordpress.Please paste the code in finction.php


function custom_post_type() {

// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'Question', 'Post Type General Name', 'twentythirteen' ),
        'singular_name'       => _x( 'Question', 'Post Type Singular Name', 'twentythirteen' ),
        'menu_name'           => __( 'Questions', 'twentythirteen' ),
        'parent_item_colon'   => __( 'Parent Movie', 'twentythirteen' ),
        'all_items'           => __( 'All Questions', 'twentythirteen' ),
        'view_item'           => __( 'View Question', 'twentythirteen' ),
        'add_new_item'        => __( 'Add New Question', 'twentythirteen' ),
        'add_new'             => __( 'Add New', 'twentythirteen' ),
        'edit_item'           => __( 'Edit Question', 'twentythirteen' ),
        'update_item'         => __( 'Update Question', 'twentythirteen' ),
        'search_items'        => __( 'Search Question', 'twentythirteen' ),
        'not_found'           => __( 'Not Found', 'twentythirteen' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
    );
   
// Set other options for Custom Post Type
   
    $args = array(
        'label'               => __( 'Questions', 'twentythirteen' ),
        'description'         => __( 'Questions and reviews', 'twentythirteen' ),
        'labels'              => $labels,
        // Features this CPT supports in Post Editor
        'supports'            => array( 'title', 'author',),
        // You can associate this CPT with a taxonomy or custom taxonomy.
        'taxonomies'          => array( 'genres' ),
        /* A hierarchical CPT is like Pages and can have
        * Parent and child items. A non-hierarchical CPT
        * is like Posts.
        */
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
    );
   
    // Registering your Custom Post Type
    register_post_type( 'Questions', $args );

}


/* Adds a box to the main column on the Post and Page edit screens */
function dynamic_add_custom_box() {
          add_meta_box(
        'dynamic_sectionid',
        'Right Answer',
        'dynamic_inner_custom_box',
        'questions',
        'advanced',
        'high'
    );
}

No comments:

Post a Comment