How WordPress Custom Post Types Makes Updating Easier for your Clients


By

A great challenge for any WordPress developer is ensuring that when the time comes to launch your new project, your clients will be able to make basic updates as needed. While there are many steps you can take to customize the WordPress admin area, this article will focus on one of the most important: WordPress Custom Post Types. If you’re not familiar with what they are, I recommend reading Konstantin Kovshenin’s post introducing them.

A Custom Post Type is a great way to organize any specialized content on your website. It’s especially effective when you have a client that will be maintaining their own site. It provides a more direct and visual interface for users. In short, they won’t have to search around for the content they wish to update.

In this simple example, I’ll show you how it helped one of my clients easily update a little area of their site.

The Challenge

My client owns her own Yoga studio. For many years, she had an old school static HTML website. Thankfully, she saw the light and decided it was time to convert to WordPress. She was looking for a way to quickly display important information on the website’s home page. Specifically, she wanted to display weather-related cancellation notices.

The (Old) Solution

Back in the day, I might have decided to create a new WordPress category and set the site’s theme up to automatically display any weather-related information. While this would have worked just fine on the front end of the site, it more than likely would have confused my client when making updates in the back end. She would have had to login, click on Posts, add a new post and remember to select the correct category when publishing. Not the hardest thing in the world to do. But, thanks to Custom Post Types, it would have been more steps than necessary and a little more difficult to remember.

The Custom Post Type Solution

Instead of going the old-fashioned route, I decided to simply create a new post type called Weather Alerts. That way, all the client would need to remember to do is login, click on Weather Alerts and edit the single post inside. Much simpler, no?

Here’s how it’s done:

1. Create it on the Back End
There are a couple of different ways to go about creating your own Custom Post Type. You can either paste some code into your theme’s functions.php file:

add_action( ‘init’, ‘create_post_type’ );
function create_post_type() {
register_post_type( ‘weather_alert’,
array(
‘labels’ => array(
‘name’ => __( ‘Weather Alerts’ ),
‘singular_name’ => __( ‘Weather Alerts’ )
),
‘public’ => true,
‘has_archive’ => false,
‘rewrite’ => array(‘slug’ => ‘weather’)
)
);
}

Or, there’s a really nice plugin available called Custom Post Type UI. It gives you a nice and simple way to create and edit posts types inside the WordPress admin area. You can easily configure post types with a number of different options such as whether there should be an archive of posts, is there a hierarchy, should it be included in the site’s search, etc. Taxonomies can also be created and edited.

Plus, when you’ve created your post type, the plugin will even give you code to copy and paste in your theme’s functions.php file. That’s great if you want to disable the plugin at some point while still keeping any custom post types you have created.

Either way is simple enough. The plugin just gives you a simpler WYSIWYG method for getting things done.

2. Display it on the Front End
In this example, we just wanted to show the Weather Alerts post type in a little spot on the site’s home page. For that, it was a matter of creating that spot in the site’s theme and pasting in this code:

 1, post_type => ‘weather_alert’ );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :   setup_postdata($post); ?>

Of course, if you’re creating a post type that will be used to keep a running archive of posts, that can be setup rather easily as well. And, if you wanted to create a custom page template for that post type, simply create a template in your theme (archive-post-type-name.php for the archive page and single-post-type-name.php for a single post).

Custom Post Types give us a really nice way to separate important content. Your clients will greatly appreciate the extra effort you made to make their lives that little bit easier.

This is really just the tip of the iceberg. Custom post types can be used in so many creative ways. I encourage you to dig in and find ways to incorporate them into your WordPress projects.

Related Topics


Top
This page may contain affiliate links. At no extra cost to you, we may earn a commission from any purchase via the links on our site. You can read our Disclosure Policy at any time.