Easiest way to add custom post type in Wordpress

Easiest way to add custom post type in WordPress

Today we will create a custom post type in wordpress

Working as WordPress developer requires a lot of skills and knowledge of all WordPress components ,

Even if you are not professional you might face a point of time where you might want to add custom post type in your website.I will explain in easy way so that you can under stand it easily.

WordPress by default in the box provides us posts and pages where we can add content but what if you want something similar to posts but don’t want to use original posts for it

For example if you want to add Articles for sports and games by using custom post type you can add articles for sports and can add gaming posts separately in posts back end option.

So lets create a custom post type

before anything we need to register custom post type you can choose any name you want for it, make sure you add

below given content in functions.php .this file will be inside of your theme.



// custom post type main function
function create_customposttype() {
    register_post_type( 'sports ',
            'labels' => array(
                'name' =>'Sports',
                'singular_name' => 'Sports'
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'sports '),
            'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
add_action( 'init', 'create_customposttype' );
// hook for function to theme setup

how to add custom post type

You can see above code added the custom post type named “Sports”.

Now we can add content just like we do in posts after adding content ,where ever you want to display this content it is going to be done but below given code




                                           'sports', 'posts_per_page' => 3 );
			$the_query = new WP_Query( $args ); 
		 	if ( $the_query=>have_posts() ) :
				while ( $the_query=>have_posts() ) : $the_query=>the_post(); 

custom post type

custom post type

Hope you liked this guide if you want to support then please share this post with others and do like it .
And do join us , be a part .Register with us for getting latest news and updates.