post_type wordpress code example
Example 1: wordpress get post type
// Retrieves the post type of the current post or of a given post.
get_post_type( int|WP_Post|null $post = null )
Example 2: wordpress create new post type
/*
- The function you want for creating a custom wordpress post type is
register_post_type()
- https://developer.wordpress.org/reference/functions/register_post_type/
- To add more meta boxes to the post type search for the support items in the
above link.
- Below is a basic implementation of the function to register video post type
*/
register_post_type( 'video',
array(
'labels' => array(
'name' => 'Videos',
'singular_name' => 'Video'
),
'public' => true,
'has_archive' => true,
'rewrite' => array(
'slug' => 'videos'
),
'exclude_from_search'=> true
,
'supports' => array(
'title','editor','thumbnail'
)
)
);