How To Wp Create Post Type In Wordpress

[Solved] How To Wp Create Post Type In Wordpress | Php - Code Explorer | yomemimo.com
Question : add Custom post type wordpress

Answered by : ali-dark

function iranelementor_posttype() { register_post_type( 'musics', array( 'labels' => array( 'name' => __( 'musics' ), 'singular_name' => __( 'music' ) ), 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'musics'), ) );
}
add_action( 'init', 'iranelementor_posttype' );
/*
* Creating a function to create our CPT
*/
function custom_post_type() {
// Set UI labels for Custom Post Type $labels = array( 'name' => _x( 'musics', 'Post Type General Name', 'twentythirteen' ), 'singular_name' => _x( 'music', 'Post Type Singular Name', 'twentythirteen' ), 'menu_name' => __( 'musics', 'twentythirteen' ), 'parent_item_colon' => __( 'Parent music', 'twentythirteen' ), 'all_items' => __( 'All musics', 'twentythirteen' ), 'view_item' => __( 'View music', 'twentythirteen' ), 'add_new_item' => __( 'Add New music', 'twentythirteen' ), 'add_new' => __( 'Add New', 'twentythirteen' ), 'edit_item' => __( 'Edit music', 'twentythirteen' ), 'update_item' => __( 'Update music', 'twentythirteen' ), 'search_items' => __( 'Search music', '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' => __( 'musics', 'twentythirteen' ), 'description' => __( 'music news and reviews', 'twentythirteen' ), 'labels' => $labels, // Features this CPT supports in Post Editor 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ), // 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( 'musics', $args );
}
add_action( 'init', 'custom_post_type', 0 );

Source : https://iranelementor.com/%D8%A7%DB%8C%D8%AC%D8%A7%D8%AF-%D9%BE%D8%B3%D8%AA-%D8%AA%D8%A7%DB%8C%D9%BE-%D8%B3%D9%81%D8%A7%D8%B1%D8%B4%DB%8C-%D8%AF%D8%B1-%D9%88%D8%B1%D8%AF%D9%BE%D8%B1%D8%B3/ | Last Update : Thu, 14 Jul 22

Question : how to wp create post type in wordpress

Answered by : uptight-unicorn-31rf541q9ool

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Our custom post type function
function create_posttype() { register_post_type( 'movies', // CPT Options array( 'labels' => array( 'name' => __( 'Movies' ), 'singular_name' => __( 'Movie' ) ), 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'movies'), 'show_in_rest' => true, ) );
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

Source : https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/ | Last Update : Tue, 01 Feb 22

Answers related to how to wp create post type in wordpress

Code Explorer Popular Question For Php