Custom post type in WordPress

By | October 26, 2014

Custom Post Type (CPT) in wordpress is very interesting facts to achieve what ever you want to implement in your website that developed base on WordPress Platform. instead of adding your specific category in default wordpress post type you may create your own custom post type and display it with SEO friendly url with category wise.

custom post type in wordpress

Example : For News section you want to set up separately from WordPress default post type with various news category than Register Custom Post type cst_new in WordPress by adding following code in theme functions.php file

If you want to insert category slug of custom post type taxonomy between custom post type and post

Update above code with following :

Ref : https://wordpress.org/support/topic/insert-category-of-taxonomy-between-custom-post-type-and-post

To Display custom post type in website front end create template page with your theme default template page copy paste code and change it default wp_query to

Create Archive page for Custom post type copy the code from your theme’s archive.php file and paste it in your new file that created with name archive-{customposttype}.php file. Then add style to design it according to your heart’s desire.
A very basic archive file would look like this:

Note** : to avoid slug conflict issue (page not found ) with custom post type set different different slug for custom post type slug, cpt category slug, cpt type slug.

Also while you create page with your newly created template file for display custom post type post choose different slug that does not used for registered Custom post type, cpt category and cpt tag.

In above example we used same News slug for register custom post type & Category so it throw Not found error while click on pagination link

Leave a Reply

Your email address will not be published. Required fields are marked *