Today’s been busy enough that I haven’t had the opportunity to put up some new work on it, but over the weekend, I was able to whip up the code to put together the custom post type I’d like to use for podcasts. (My original post on the project is here.)

My guides for this were the well-exampled Codex entry, Justin Tadlock’s posts on the matter, and Konstantin Kovshenin’s excellent posts as well. My code is structured after the example in the Codex with a little bit of experimentation:

# Let's get things started and fire up the custom post type for Podcasts.
add_action('init', 'simple_podcast_init');
function simple_podcast_init()
{
	$labels = array(
		'name' => _x('Podcasts', 'post type general name'),
		'singular_name' => _x('Podcast', 'post type singular name'),
		'add_new' => _x('Add New', 'podcast'),
		'add_new_item' => __('Add New Podcast'),
		'edit_item' => __('Edit Podcast'),
		'new_item' => __('New Podcast'),
		'view_item' => __('View Podcast'),
		'search_items' => __('Search Podcasts'),
		'not_found' => __('No podcasts found'),
		'not_found_in_trash' => __('No podcasts found in Trash'),
		'parent_item_colon' => ''
	);
	$args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true,
		'query_var' => true,
		'capability_type' => 'post',
		'taxonomies' => array('post_tag', 'category'),
		'hierarchical' => false,
		'menu_position' => 5,
		'supports' => array('title','editor','author','thumbnail','excerpt','comments','revisions')
	);
	register_post_type('podcast',$args);
}

This successfully registers the custom post type and its behaviors (though I’m not certain I like the taxonomies and may need to move to something else in the future), but there remains a problem: upon activating the plugin, any attempt to view a podcast results in a 404 from the permalink.

I’ve seen references elsewhere to flushing the rewrite rules, but it’s not clear to me where in the process this should go or how it’s supposed to be called. My understanding is that I don’t want to do that every time the plugin initializes, because that’s not being a good steward of server resources. (Of course, if I visit the panel at Settings > Permalinks, everything works just like it should.)

Unfortunately, I’ve not yet seen an example of code that would properly reset the rewrite rules when this is turned on. Here’s what I tried and failed with:

# Because we're adding a rewrite, we need to flush the rules on activation.
	function simple_podcast_flush_rules()
{
		global $wp_rewrite;
		$wp_rewrite->flush_rules();
}
register_activation_hook( __FILE__ , 'simple_podcast_flush_rules' );

Does anyone reading this have a suggestion for where I might be going wrong? I eventually had to step back from it and won’t get a chance to try again until later.

Playing more with custom post types has also revealed a small flaw in my designs: the podcasts won’t “mesh” with the regular posts on the blog. Their taxonomies (as far as I can tell) can’t be shared, and the podcasts won’t display in the main feed of the blog, either.

Then again, this may or may not be a concern, depending on how one would structure the site.