How to Create Custom Post Type in WordPress

Custom post types are content types like posts and pages. Since WordPress evolved from a simple blogging platform into a robust CMS, the term post stuck to it. However, a post type can be any kind of content.

You can create your own custom post types and call them whatever you want. For example if you run a notice panel in your website, then you would probably want to create a notice post type. This post type can have different custom fields and even its own custom category structure, file upload option OR file attached field.

You just copy below code & paste in to your theme function.php file

Custom Post Type Code

// NOTICE POST TYPE

add_action(‘init’, ‘notices_register’);
function notices_register() {
$labels = array(
‘name’ => __(‘Notices’, ‘post type general name’),
‘singular_name’ => __(‘New Notices’, ‘post type singular name’),
‘add_new’ => __(‘Add Notices’, ‘notices item’),
‘add_new_item’ => __(‘Add Notices’),
‘edit_item’ => __(‘Edit Notices’),
‘new_item’ => __(‘New Notices’),
‘view_item’ => __(‘View Notices’),
‘search_items’ => __(‘Search Notices’),
‘not_found’ => __(‘Nothing found’),
‘not_found_in_trash’ => __(‘Nothing found in Trash’),
‘parent_item’ => __( ‘Parent Notices’ ),
‘parent_item_colon’ => __( ‘Parent Notices:’ )
);

$args = array(
‘labels’ => $labels,
‘public’ => true,
‘show_ui’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘has_archive’ => false,
‘rewrite’ => true, //array(‘slug’ => ‘testimonials’, ‘with_front’ => false ),
‘query_var’ => true,
‘menu_icon’ => get_stylesheet_directory_uri() . ‘/images/notice.png’,
‘menu_position’ => 4,
‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’, ‘revisions’)
);

register_post_type( ‘notices’ , $args );
flush_rewrite_rules();
register_taxonomy( “notices-categories”,
array( “notices” ),
array( “hierarchical” => true,
“show_ui” => true,
“show_tagcloud” => false,
“hasArchive” => true,

“labels” => array(‘name’=>”Notices Categories”,’add_new_item’=>”Add New Category”),
“singular_label” => __( “Category” ),
“rewrite” => array( ‘slug’ => ‘notices-cat’,
// This controls the base slug that will display before each term
‘with_front’ => false)) );

add_action(“admin_init”, “notice_info”);
function notice_info(){
add_meta_box(‘notice_info_meta’, ‘Add Notice Information’, ‘notice_info_fnc’, ‘notices’, ‘normal’, ‘high’);
}
function notice_info_fnc(){
global $post;
if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) return $post_id;
$custom = get_post_custom($post->ID);
$ad_image = $custom[“ad_image”][0];
?>
<div class=”inside” style=”overflow:hidden;”>
<div style=”float:left; width:49%; margin-right:1%;”>
<p><strong>Upload Your File Here</strong><br />
<script>
jQuery(document).ready(function($){
var custom_uploader;
$(‘#upload_image_button’).click(function(e) {
e.preventDefault();
//If the uploader object has already been created, reopen the dialog
if (custom_uploader) {
custom_uploader.open();
return;
}
//Extend the wp.media object
custom_uploader = wp.media.frames.file_frame = wp.media({
title: ‘Choose File’,
button: {
text: ‘Choose File’
},
multiple: true
});
//When a file is selected, grab the URL and set it as the text field’s value
custom_uploader.on(‘select’, function() {
console.log(custom_uploader.state().get(‘selection’).toJSON());
attachment = custom_uploader.state().get(‘selection’).first().toJSON();
$(‘#upload_image’).val(attachment.url);
});
//Open the uploader dialog
custom_uploader.open();
});
});
</script>
<label for=”upload_image”>
<input id=”upload_image” type=”text” size=”36″ name=”ad_image” placeholder=”https//” value=”<?= $custom[“ad_image”][0] ?>” />
<input id=”upload_image_button” class=”button” type=”button” value=”Upload Doc. File” />
<br />Enter a URL or upload your file</label>
</div>
</div>
<?php }
}
// Save

add_action(‘save_post’, ‘save_notices’);
function save_notices(){
global $post;
if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE )
return;
if($post){
update_post_meta($post->ID, “pdf_file”, $_POST[“pdf_file”]);
update_post_meta($post->ID, “ad_image”, $_POST[“ad_image”]);
}
}
add_filter(“manage_edit-notices_columns”, “notices_edit_columns”);
function notices_edit_columns($columns){
$columns = array(
“cb” => “<input type=\”checkbox\” />”,
“title” => “Name / Title”,
“aboutnotices” => “Notices Short Details”,
“notices-cats” => “Category”,
“noticesthumb” => “Thumbnail”,
);
return $columns;
}
add_action(“manage_posts_custom_column”, “notices_custom_columns”);
function notices_custom_columns($column){
global $post;
switch ($column)
{
case “aboutnotices”:
the_excerpt();
break;
case “notices-cats”:
echo get_the_term_list($post->ID, ‘notices-categories’, ”, ‘, ‘,”);
break;
case “noticesthumb”:
if ( has_post_thumbnail() ) :
the_post_thumbnail(array (180, 120));
else :
echo ‘No featured image selected’;
endif;
break;
}
}

44 Responses to “How to Create Custom Post Type in WordPress”

  1. Thank you a lot for sharing this with all folks you really recognise what you are talking about! Bookmarked.post, Kindly also talk over with my web site =). We can have a link exchange agreement among us!

  2. Thank you a lot for sharing this with all people you actually realize what you are talking approximately! Bookmarked.postwholesale nfl jerseys, Kindly additionally seek advice from my site =). We can have a link change contract among us!

  3. Irving says:

    Wow, this post is fastidious, my younger sister is analyzing these things, therefore I am going
    to tell her.

  4. Hello there, just changed into aware of your weblog via Google, and located that it is really informative. I going to watch out for brussels. I will be grateful if you happen to continue this in future. Lots of other folks shall be benefited from your writing. Cheers!

  5. Hi there, simply was aware of your blog thru Google, and found that it’s truly informative. I am gonna be careful for brussels. I will be grateful if you happen to continue this in future. Numerous other people will probably be benefited from your writing. Cheers!

  6. Hi there, just became aware of your blog through Google, postcheap nfl jerseys chinaand found that it is truly informative cheap nfl jerseys. I going to watch out for brussels. Il appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers!

  7. Thank you for the good writeup. It actually was once a enjoyment account it. Glance complicated to more delivered agreeable from you! However, how could we keep up a correspondence?

  8. Hi there, just turned into alert to your weblog thru Google, and found that it’s truly informative. I gonna watch out for brussels. Il appreciate in case you proceed this in future. A lot of folks will be benefited from your writing. Cheers!

  9. Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I acquire actually enjoyed account we supply cheap nfl jerseys your blog posts. Anyway I will be subscribing to your feeds and even I achievement you access consistently quickly.

  10. Discover what’s the deal with ingbacks? According to Wikipedia, WP supports automatic pingbacks where all the links in a published article can be pinged when the article is published?we supply cheap nfl jerseys That explains why I get messages about new comments? when posting an edit that cross-references another post of my own. Info on trackbacks and pingbacks in WP here.

  11. A person essentially assist to make critically articles I might state. postwholesale nfl jerseysThat is the first time I frequented your website page and so far? I amazed with the analysis you made to make this particular publish extraordinary. Wonderful process!

  12. Thank you a bunch for sharing this with all of us you actually recognise what you’re speaking about! Bookmarked.postcheap jerseys, Kindly additionally discuss with my site =). We can have a link trade agreement between us!

  13. nfl gear says:

    Thank you for the good writeup. It actually was a amusement account it. Look complex to more delivered agreeable from you! However, how could we keep in touch?

  14. Thanks a lot for sharing this with all folks you actually recognize what you’re speaking approximately! Bookmarked.postcheap jerseys, Kindly additionally discuss with my site =). We will have a link change agreement among us!

  15. I’m extremely impressed with your writing skills postcheap nike nfl jerseys and also with the layout on your blog with cheap nfl jerseys. Is this a paid theme or did you customize it yourself? Anyway keep up the nice quality writing, it is rare to see a nice blog like this one these days

  16. Thanks for the auspicious writeup. It actually was a entertainment account it. Look complicated to far introduced agreeable from you! By the way, how can we keep in touch?

  17. We’re a group of volunteers and starting a new scheme in our community. Your web site offered us with valuable info to work on cheap nfl jerseys china. You’ve done an impressive job and our whole community will be thankful to you.

  18. Attractive section of content. I just stumbled upon your site and in accession capital to assert that I acquire actually enjoyed account we supply cheap nfl jerseys your blog posts. Anyway Il be subscribing to your feeds and even I achievement you access consistently rapidly.

  19. In the WordPress support forum, there are from time to time questions abut trackbacks. I haven’t used it myself, but I found a good tutorial on the OptiNiche cheap nfl jerseys china blog.

  20. hello there and thank you for your info ?I have definitely picked up something new from proper here postcheap nfl jerseys china. I did however experience several technical issues the use of this website, as I skilled to reload the web site lots of instances prior to I may just get it to load properly. I had been thinking about in case your web hosting is OK? Now not that I’m complaining, however slow loading instances times will sometimes affect your placement in google and could injury your quality ranking if ads and ****|advertising|advertising|advertising and *** with Adwords. postcheap jerseysAnyway I adding this RSS to my email and could look out for much extra of your respective interesting content. Make sure you replace this once more soon.

  21. hello there and thank you on your information ?I have certainly picked up anything new from proper here postcheap nike nfl jerseys. I did alternatively expertise several technical points the usage of this website, as I experienced to reload the web site a lot of times prior to I may get it to load properly. I had been brooding about if your hosting is OK? Now not that I am complaining, but slow loading instances times will often have an effect on your placement in google and could injury your high quality score if ads and ****|advertising|advertising|advertising and *** with Adwords. postcheap nfl jerseysWell I am adding this RSS to my email and can glance out for a lot extra of your respective intriguing content. Make sure you replace this once more very soon.

  22. hello there and thanks on your info ?I definitely picked up something new from right here postwholesale nfl jerseys. I did then again expertise a few technical points using this site, as I experienced to reload the site many times prior to I may just get it to load correctly. I were puzzling over if your hosting is OK? Not that I am complaining, however slow loading cases instances will very frequently impact your placement in google and can damage your high quality ranking if advertising and ****|advertising|advertising|advertising and *** with Adwords. postcheap jerseysWell I am including this RSS to my e-mail and can look out for much extra of your respective exciting content. Make sure you replace this once more soon.

  23. I’m really impressed with your writing skills postwholesale nfl jerseys as well as with the layout on your weblog with cheap nfl jerseys. Is this a paid theme or did you modify it yourself? Either way keep up the nice quality writing, it rare to see a nice blog like this one these days

  24. Somebody essentially assist to make significantly articles I would state. postwholesale nfl jerseysThis is the very first time I frequented your website page and so far? I surprised with the analysis you made to make this particular put up amazing. Great task!

  25. Hi there, just become alert to your weblog via Google, and found that it is truly informative. I am going to watch out for brussels. Il appreciate should you proceed this in future. A lot of other people will be benefited from your writing. Cheers!

  26. I been exploring for a little for any high quality articles or blog posts on this kind of area postcheap nfl jerseys. Exploring in Yahoo I at last stumbled upon this web site. Reading this info So i happy to convey that I’ve an incredibly good uncanny feeling I discovered exactly what I needed. I most certainly will make certain to don’t forget this web site and give it a glance on a constant basis.

  27. Thanks for another magnificent article. Where else could anyone get that type of information in such an ideal way of writing? I have a presentation next week, and I’m on the look for such information.

  28. In the WordPress support forum, there are from time to time questions abut trackbacks. I haven’t used it myself, but I found a good tutorial on the OptiNiche cheap nfl jerseys china blog.

  29. Hi there, just became alert to your blog through Google, postcheap nike nfl jerseysand found that it’s really informative cheap nfl jerseys. I going to watch out for brussels. I will be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!

  30. Wow, fantastic blog layout! How long have you been blogging for? you made blogging look easy to cheap nfl jerseys china. The overall look of your website is excellent, postcheap jerseyslet alone the content!

  31. Thanks for another fantastic post. Where else could anybody get that kind of info in such an ideal way of writing? I have a presentation next week, and I’m on the look for such information.

  32. Wow, wonderful blog layout! How long have you been blogging for? you made blogging look easy to cheap nfl jerseys china. The overall look of your site is excellent, postcheap nfl jerseys chinalet alone the content!

  33. We’re a group of volunteers and starting a new scheme in our community. Your web site offered us with valuable information to work on cheap nfl jerseys china. You’ve done a formidable job and our whole community will be grateful to you.

  34. hey there and thank you in your info ?I definitely picked up anything new from proper here postcheap nike nfl jerseys. I did alternatively experience a few technical issues the use of this website, as I skilled to reload the web site a lot of times previous to I may just get it to load properly. I had been thinking about if your web host is OK? Now not that I’m complaining, however sluggish loading circumstances instances will sometimes impact your placement in google and can harm your high quality ranking if ads and ****|advertising|advertising|advertising and *** with Adwords. postcheap jerseysAnyway I am adding this RSS to my e-mail and can look out for much more of your respective interesting content. Make sure you update this again very soon.

  35. I’m really impressed with your writing skills postwholesale nfl jerseys and also with the layout on your blog with cheap nfl jerseys. Is this a paid theme or did you customize it yourself? Anyway keep up the excellent quality writing, it rare to see a nice blog like this one these days

  36. I do agree with all the ideas you have presented in your postcheap jerseys. They’re really convincing and will certainly work. Still, the posts are too short for starters. Could you please extend them a little from next time? Thanks for the post.

  37. As a side note, the more we can use trackbacks, pingbacks, and backlinks to spread the love and our message, the better.we supply cheap nfl jerseys I encourage you to figure out how to use these tools as they can really make our words online much more effective and heard.

  38. I believe that is among the so much significant info for me. And i’m happy studying your article. But wanna statement on some normal things, The website taste is ideal,post the articles is actually nice D.Excellent job, cheers

  39. Hi there, just was alert to your blog thru Google, and found that it’s really informative. I am gonna be careful for brussels. I will appreciate if you proceed this in future. A lot of other folks will probably be benefited from your writing. Cheers!

  40. In the WordPress support forum, there are from time to time questions abut trackbacks. I haven’t used it myself, but I found a good tutorial on the OptiNiche cheap nfl jerseys china blog.

  41. Since I didn’t really understand how this works,we supply cheap nfl jerseys I did some searching and found an outstanding WordPress Trackback Tutorial that explains much of what I was finding confusing.

  42. Thanks for another fantastic article. Where else could anybody get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

  43. hey there and thank you for your info ?I have definitely picked up something new from proper here postcheap nike nfl jerseys. I did however experience several technical points the usage of this web site, since I skilled to reload the site many times prior to I could get it to load properly. I were considering in case your hosting is OK? Now not that I am complaining, however slow loading circumstances instances will often affect your placement in google and can harm your high-quality rating if ads and ****|advertising|advertising|advertising and *** with Adwords. postcheap jerseysWell I am including this RSS to my e-mail and could glance out for much extra of your respective interesting content. Ensure that you update this again very soon.

  44. Wow, marvelous blog layout! How long have you been blogging for? you make blogging look easy to cheap nfl jerseys china. The overall look of your website is magnificent, postas well as the content!

Leave a Comment to cheap replica nfl jerseys

Comment authors age:




How to Create Custom Shortcode in WordPress

Create File Upload Option with jQuery in WordPress