Working with custom post types for the last 3 or 4 years has on the whole been great. However there was always one thing that I found lacking and that was the lack of an (editable) post type description. Therefore I set about to try and change this, adding some extras along the way. Let me introduce the WP Post Type Meta WordPress plugin.
I must start off this post by letting you know that this idea is not new. In fact my idea for this came from Steven Jones in his post 5 Improvements to WordPress’ User Experience. In this post Steven added a simple link to a plugin that adds a post type description to custom post types. Essentially this is what WP Post Type Meta does “out of the box”, however I wanted to take this further and allow further meta to be added to custom post types.
The need for this was seen when I was working on sites that made use of the term description field in a taxonomy term. This description is often displayed at the top of the archive for that term to indicate the nature of the posts found in the term archive. This was something that a lot of my clients wanted for custom post types. For example many want an FAQ section and I often deliver this through a custom post type with an accordion style jQuery addition on the front end. The post type archive acts as the FAQ page. However many clients wanted to have a paragraph of text appear at the top of this archive to explain the page. The problem them comes as to how to allow the client to edit the text. There are other ways to achieve a solution to this such as a page that is pulled in at the top and also a theme option style settings, however I was not really happy with either. Steven’s post type description plugin did the job.
This got me thinking that we could actually add other fields to the post type description page added in the admin. For example what if you had a post type about products and you wanted to add a standard sizing link to a PDF that would show on the archive page at the top in useful info. You can easily add a text input box and add your link into that or even a post type select input to choose a page for the sizing information.
This is what the WP Post Type Meta plugin does. It provides an additional sub admin menu for each custom post type in your site named {Post Type} Meta. By default on the page is a description box to add a post type description, however the plugin is extensible and easily allows you to add other fields including text, textarea, WYSISYG, select and checkbox inputs. The post type description field is added in this way.
All of the plugin meta data is stored in the WordPress option named wpptm_meta
as an array. Each piece of meta added is prefixed with the post type name. For example to get the post type description field you would use the following:
https://gist.github.com/wpmark/2dbb0d59c898acd4adda
You can add your own fields by using the wpptm_settings
filter. The example below shows you how to add a select input:
https://gist.github.com/wpmark/8d96847316d5f46a6174
Other fields can be added in a similar way. The field above would be retrieved on the front end like so:
https://gist.github.com/wpmark/aa92cc2ee556f7d7c9f0
I have tried to build the plugin in an extensible way to allow developers to build upon and extend its functionality. I look forward to using it in the future.
You can download the WP Post Type Meta plugin on WordPress.org or add it to your site through your WordPress dashboard.
Leave a Reply