Category Archives: Custom Post Types

Notes that relate to the use of custom post types

Custom post types, taxonomies , capabilities, roles

Are you you getting the browser messages when saving a new custom post type draft?

  • Firefox: “This page is asking you to confirm that you want to leave – data you have entered may not be saved.”
  • Internet Explorer: “Are you sure you want to leave this page”
  • Chrome: “The changes you have made will be lost if you navigate away from this page”
  • “Leave page or Stay on page” when you click save draft on a new custom post type?
What happens when you do not have the right capability
What happens when you do not have the right capability
Leave or Stay message in chrome
Leave or Stay message in chrome

What happens?

You opt to leave and the post was still saved but the custom fields etc do not save.  BUT then you CAN edit the post and then add in the custom fields / meta box without any further problem (what the?)

And of course admin’s have no problem!


This appears to be because we have said that the custom post type supports the default taxonomies and possibly wordpress is trying to do something with javascript (maybe assign a default category to the custom post type) but the user is not allowed to.  However it also happens when the custom post type has tags but not categories?  But it does not happen if it just has the custom taxonomy (with the assign_terms or assign_terms=>edit_events capability).    The behaviour only occurs with default taxonomies.

Key finding:

If you are allowing your custom post type to be assigned categories and tag taxonomies like normal posts, then ANY role that is required to be able to create the custom post type while default taxonomies are supported, must also have ‘edit_posts’ capability. (Unless you have code to change the default taxonomies, but then you will be messing with the standard posts capabilities)

Arguably the wordpress default capability ‘assign_terms’ should not be mapped by default to ‘edit_posts’ as this is what is making life complicated.  Possibly a contributor should have ‘assign_terms’ capability directly?   Or one might say that it’s the sharing of taxonomies that is causing the complication.


I wanted a role that could create events but NOT also create posts.  Similarly with editors.
Custom roles can be setup to manage custom post types (in this case events) and one can isolate these capabilities.  However when one adds taxonomies (default and custom) into the mix, things get more interesting.

Default taxonomy capabilities for categories and tags

$default_caps = array(
 'manage_terms' => 'manage_categories',
 'edit_terms'   => 'manage_categories',
 'delete_terms' => 'manage_categories',
 'assign_terms' => 'edit_posts',

While one could overwrite these capabilities with say ‘assign_terms’=>’assign_terms’, then one would not be able to assign categories and tags to standard post types without also ensuring that the default roles were assigned the capability ‘assign_terms’.  All achievable, it just seems wrong to have to mess with standard wp and risk breaking other plugins.

Registering custom taxonomy means that in this case ‘edit_events’ capability is enough to be able to assign this custom taxonomy to this single custom post type

'capabilities' => array (
 'manage_terms'=> 'manage_categories',
 'edit_terms'=> 'manage_categories',
 'delete_terms'=> 'manage_categories',
 'assign_terms' => 'edit_events'  // strictly speaking need one for each new posttype ?


TIP: while you are testing this all out, a role manager plugin like Justin Tadlock’s members plugin is very helpful.  Roles and their capabilities are saved in the database and unless you ‘remove’ the role and add it again, the capabilties will not update as you might want them to.

I was actually trying to create a custom role that can assign categories, tags and custom taxonomies to your custom post type. If you give these roles ‘manage_categories’, they’ll be able to add new categories BUT still not assign a post to existing categories.  They have to have ‘edit_posts’ or obe has to override the default wp setup.


Version 1.7, event post thumbnail images and some RDATE or EXDATE bug fixes

Amr-events Version 1.7 is now available here:

Event excerpt with post thumbnail
Event excerpt with post thumbnail in hover area instead of post content
  • Fixed situation where if there where no parameters entered in widget, then no events were listed in the widget.  The widget will now pickup default parameters from the listtype like it used to.
  • Added possibility for CURL to follow redirections in case an exernal ics host has moved your ics file while you were not looking!
  • Timed certain day repeating dates (RDATES) will now show the correct time
  • Timed events with excluded dates (EXDATES) will now have events on the excluded days excluded.  Note: excluded days overwrite RDATES above if the dates and times are the same.  This is because it is possible according to the spec to have RRULES and RDATES in same event and one may wish to have an excluded date for the RRULE.  So it is possible to have the 3 co-existing, and thus a priority must be assigned.
  • If your theme supports post thumbnails or feature images, you may now include these separately in your list type.  For example, if the image is not already in your post content or added to your excerpt, then you may wish to add the post thumbnail to your event display.  Using the list type settings, you can add the post thumbnail separately to a agenda, calendar or widget listing.  Note that this stage the size will be the thumbnail size, as used by your theme.  If there is a demand to be able to create one’s own event thumbnail image size, please add your thoughts here Note that you can change your website thumbnail size via wordpress settings and plugins do exist to allow you to regenerate your old thumbnails.
Using excerpt and post thumbnail instead of post content
Using excerpt and post thumbnail instead of post content

How to use custom post types as events

The amr-events plugin events can be

Which to use? some points to note:

  • Custom post types are a way of keeping a type of post “separate” from other posts.
  • Many Some plugins may work with standard posts, but not with custom posts.  (this has improved ) Eg: social sharing buttons, map/location plugins ,  filter plugins etc.  So investigate whether you expect them to work with your events or not, before deciding which to use.
  • Even if other plugins work with custom post types, you probably need to go back to their configuration once you have added a custom post type and add the new post type in to their configuration.
  • Alternatively if you want another plugin to work with your events, but NOT with your posts – eg: a geo tagging plugin, then maybe use custom posts instead.
  • Once you have added a new custom type type (or indeed a new taxonomy) you may need to flush your permalink rewrite rules.  It is not appropriate for the plugin to do this automatically as it can be computationally expensive – it is better if you decide when to do it.  It only needs to be done after configuration changes that affect the rules.  Goto your permalinks and resave your settings.

This plugin does many things, but specifically for custom post types:

  • it adds custom post type events to your rss feed and home page if you want – just tick the check box in the settings (from version 1.1 onwards).
  • it can add taxonomies if you wish – all the code you need is there, including special taxonomy widgets.

Settings > post types

Settings specific to custom post types
Taxonomies Examples

Further Information


In researching custom post types and in particular how to add them to blog post home pages and rss feeds, I found complaints of lost custom menus, thumbnails when adding custom post types.  You can see some in the comments on Justin ‘s post on showing custom post types on the  home page. I believe that the reason for this is:

Most of the suggested code examples show setting (thus over-writing) the post types in the query, rather than checking if there any post types there already (remember  ‘post’ as a default of course) and adding to the list.

If one is using multiple plugins and themes that filter the wp-query to add post types (could be pages, attachments for thumbnail, custom menus etc)  eg with:

add_filter( 'pre_get_posts', 'a_function')

…in that case, plugins could overwrite each other’s filter criteria – it would depend on which filter got executed last.

This plugin checks first.  Also you can switch it’s version of the filter off completely.

For further information on how to use the plugin generally, see

Feedburner plugins and ical feeds

If you are using feedburner and a ical plugin that generates feeds, then please use the, rather than the feedsmith plugin.

The FD plugin allows for the possibility of some other feed (like an ical feed naturally!) and so will not hijack your ics feed like the feedsmith one does.


  • a simple hack to the google feedsmith plugin to check the global $feed variable and bail if it = ‘ics’ would also do the trick!
  • or if you maintain good coding standards and don’t like editing external plugins (not a good idea generally!), then you could muck around with the wordpress action template_redirect and see if you can remove the feedburner redirect IF it is a ics feed.

Event editing plugin with full ics/ical feed

The amr-events plugin is in an almost alpha state, suitable for some testing (Still some debug statements lurking around!) .  Get a preview by testing it yourself at

It aims to provide full implementation of the ical RFC 5445 specification, while reatining the ability to be scaled down for more basic use.  It has either simple built in location to map link functionality, or will integrate with a number of “geo” plugins.

The ics feed has been tested with a number of calendar programs including google.

For more details:

Event locations, geo tags for custom post types

I am finalising my new plugin that will allow creation of Ical events within wordpress.  The Ical spec provides for a location and geotags for an event.  The existing event list plugin  shows a google map link for the event if these components exist.

So the new plugin will allow entry of a location and/or integrate with other location plugins. There are some sweet geo or location plugins available, so I thought I would keep my location meta box input simple and allow integration with some of these other plugins if anyone required more sophistication.    I have tested the new plugins see if they play nicely with custom post types (although my plugin will also work with normal posts too), and use the wordpress databse appropriately.  Custom Post Type support is actually quite easy to add, so please check the latest versions.

So far I have looked at:

WP Geo

wp-geo metabox
  • Ben Huson is currently working on optional custom post type support.
  • His plugin uses straight forward post-meta which makes it easy to integrate
  • Optional control over where location data shows if at all in post view.


geomashup metabox
  • This plugin uses custom tables, so will only be able to access their data if their plugin is active (uses their DB class to extract the data)
  • It appears to automatically support custom post types(ie the metabox appears on all post types). Ideally this should be optional as per Ben Huson’s version above (dev version for now).
  • Has a fairly unique feature of allowing one to save and reuse locations.  Does some cacheing.


Gelocation plugin metabox
  • Also stores it geo-data nicely in the user meta table, so will integrate with this too.
  • Map shows on hover on the address in the post.  There is some option as to where/how this location link appears.
  • Does not support custom post types yet.
  • works with the wordpress iphone app.
  • v0.1.1 breaks some of the admin JavaScript, not disastrously – affects the arrow down of menu show/hide. Common problem when a plugin includes latest UI.  Very minor – one can still click them the menu title to open it up.

gpress removed.


If anyone would like to suggest other post location plugins for consideration in offering integration, please comment below.

Since there are a number of these similar plugins, the location plugin that will come with the ical events plugin will be much simpler.  It will probably not have the map displayed every time you edit the post, or display the post. It will have a link to verify that the address is adequate to bring up the correct map view and/or get the latitude and longitude.

Draft version of the “simple” post location plugin metabox