Search
 
SCRIPT & CODE EXAMPLE
 

PHP

custom post type

/*
* Creating a function to create our CPT
*/
 
function custom_post_type() {
 
// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'Movies', 'Post Type General Name', 'twentytwenty' ),
        'singular_name'       => _x( 'Movie', 'Post Type Singular Name', 'twentytwenty' ),
        'menu_name'           => __( 'Movies', 'twentytwenty' ),
        'parent_item_colon'   => __( 'Parent Movie', 'twentytwenty' ),
        'all_items'           => __( 'All Movies', 'twentytwenty' ),
        'view_item'           => __( 'View Movie', 'twentytwenty' ),
        'add_new_item'        => __( 'Add New Movie', 'twentytwenty' ),
        'add_new'             => __( 'Add New', 'twentytwenty' ),
        'edit_item'           => __( 'Edit Movie', 'twentytwenty' ),
        'update_item'         => __( 'Update Movie', 'twentytwenty' ),
        'search_items'        => __( 'Search Movie', 'twentytwenty' ),
        'not_found'           => __( 'Not Found', 'twentytwenty' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentytwenty' ),
    );
     
// Set other options for Custom Post Type
     
    $args = array(
        'label'               => __( 'movies', 'twentytwenty' ),
        'description'         => __( 'Movie news and reviews', 'twentytwenty' ),
        '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'     => 'post',
        'show_in_rest' => true,
 
    );
     
    // Registering your Custom Post Type
    register_post_type( 'movies', $args );
 
}
 
/* Hook into the 'init' action so that the function
* Containing our post type registration is not 
* unnecessarily executed. 
*/
 
add_action( 'init', 'custom_post_type', 0 );
Comment

display custom post type

$args = array(  
        'post_status' => 'publish',
        'posts_per_page' => 5,  
        
		);
	
    $loop = new WP_Query( $args ); 
        
    while ( $loop->have_posts() ) : $loop->the_post(); 
        the_title(); 
	the_excerpt();
    endwhile;
Comment

add Custom post type wordpress

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 );
Comment

custom post type wp

Copy
Expand code
/**
 * Register a custom post type called "book".
 *
 * @see get_post_type_labels() for label keys.
 */
function wpdocs_codex_book_init() {
	$labels = array(
		'name'                  => _x( 'Books', 'Post type general name', 'textdomain' ),
		'singular_name'         => _x( 'Book', 'Post type singular name', 'textdomain' ),
		'menu_name'             => _x( 'Books', 'Admin Menu text', 'textdomain' ),
		'name_admin_bar'        => _x( 'Book', 'Add New on Toolbar', 'textdomain' ),
		'add_new'               => __( 'Add New', 'textdomain' ),
		'add_new_item'          => __( 'Add New Book', 'textdomain' ),
		'new_item'              => __( 'New Book', 'textdomain' ),
		'edit_item'             => __( 'Edit Book', 'textdomain' ),
		'view_item'             => __( 'View Book', 'textdomain' ),
		'all_items'             => __( 'All Books', 'textdomain' ),
		'search_items'          => __( 'Search Books', 'textdomain' ),
		'parent_item_colon'     => __( 'Parent Books:', 'textdomain' ),
		'not_found'             => __( 'No books found.', 'textdomain' ),
		'not_found_in_trash'    => __( 'No books found in Trash.', 'textdomain' ),
		'featured_image'        => _x( 'Book 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( 'Book archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'textdomain' ),
		'insert_into_item'      => _x( 'Insert into book', '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 book', '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 books 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( 'Books 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( 'Books 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' => '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 );
}

add_action( 'init', 'wpdocs_codex_book_init' );
Comment

custom post type

.wp-block-code {
	border: 0;
	padding: 0;
}

.wp-block-code > div {
	overflow: auto;
}

.hljs {
	box-sizing: border-box;
}

.hljs.shcb-code-table {
	display: table;
	width: 100%;
}

.hljs.shcb-code-table > .shcb-loc {
	color: inherit;
	display: table-row;
	width: 100%;
}

.hljs.shcb-code-table .shcb-loc > span {
	display: table-cell;
}

.wp-block-code code.hljs:not(.shcb-wrap-lines) {
	white-space: pre;
}

.wp-block-code code.hljs.shcb-wrap-lines {
	white-space: pre-wrap;
}

.hljs.shcb-line-numbers {
	border-spacing: 0;
	counter-reset: line;
}

.hljs.shcb-line-numbers > .shcb-loc {
	counter-increment: line;
}

.hljs.shcb-line-numbers .shcb-loc > span {
	padding-left: 0.75em;
}

.hljs.shcb-line-numbers .shcb-loc::before {
	border-right: 1px solid #ddd;
	content: counter(line);
	display: table-cell;
	padding: 0 0.75em;
	text-align: right;
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
	white-space: nowrap;
	width: 1%;
}
// Register Custom Post Type - Workshop
function kp_workshops() {

	$args = array(
		'label' =>; __( 'Workshop', 'kp_workshops' ),
		'description' =>; __( 'Workshop listing', 'kp_workshops' ),
		'labels' =>; $labels,
		'supports' =>; array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', 'custom-fields' ),
		'taxonomies' =>; array( 'category' ),
		'hierarchical' =>; false,
		'public' =>; true,
		'show_ui' =>; true,
		'show_in_menu' =>; true,
		'menu_position' =>; 20,
		'menu_icon' =>; 'dashicons-welcome-learn-more',
		'show_in_admin_bar' =>; true,
		'show_in_nav_menus' =>; true,
		'can_export' =>; true,
		'has_archive' =>; true,
		'exclude_from_search' =>; false,
		'publicly_queryable' =>; true,
		'capability_type' =>; 'page',
		'show_in_rest' =>; true,
	);

	register_post_type( 'workshops', $args );

}
add_action( 'init', 'kp_workshops', 0 );
Comment

PREVIOUS NEXT
Code Example
Php :: try catch in laravel 
Php :: is home page if wordpress 
Php :: php connect to data base 
Php :: curl header log php 
Php :: how to create new project in laravel 
Php :: format time laravel 
Php :: laravel run a specific migration 
Php :: randstring php 
Php :: php hash password 
Php :: php date modify plus 1 day 
Php :: phpmailer send attachment 
Php :: where_in codeigniter 
Php :: wp get category by id 
Php :: make a object php 
Php :: laravel join 
Php :: codeigniter order by random 
Php :: how to show validation error in laravel 8 
Php :: PHP strtotime() Function 
Php :: laravel if syntax 
Php :: foreach total sum 
Php :: php month single digit 
Php :: Target class [Controller] does not exist. 
Php :: remove last character from string in php 
Php :: how to add property to an exsisting object in php 
Php :: php sql get single value 
Php :: ubuntu install lamp and phpmyadmin 
Php :: php line break in echo 
Php :: how to check mobile or desktop in php 
Php :: php capitalize first letter 
Php :: <?php echo do_shortcode(); ? with variable 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =