__('Podcasts'), 'singular_label' => __('Podcast'), 'public' => true, 'show_ui' => true, // UI in admin panel '_builtin' => false, // It's a custom post type, not built in '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array("slug" => "podcast"), // Permalinks 'query_var' => "podcast", // This goes to the WP_Query schema 'supports' => array('title','author', 'excerpt', 'editor' /*,'custom-fields'*/) // Let's use custom fields for debugging purposes only )); add_filter("manage_edit-podcast_columns", array(&$this, "edit_columns")); add_action("manage_posts_custom_column", array(&$this, "custom_columns")); // Register custom taxonomy register_taxonomy("speaker", array("podcast"), array("hierarchical" => true, "label" => "Speakers", "singular_label" => "Speaker", "rewrite" => true)); // Admin interface init add_action("admin_init", array(&$this, "admin_init")); add_action("template_redirect", array(&$this, 'template_redirect')); // Insert post hook add_action("wp_insert_post", array(&$this, "wp_insert_post"), 10, 2); } function edit_columns($columns) { $columns = array( "cb" => "", "title" => "Podcast Title", "p30_description" => "Description", "p30_length" => "Length", "p30_speakers" => "Speakers", ); return $columns; } function custom_columns($column) { global $post; switch ($column) { case "p30_description": the_excerpt(); break; case "p30_length": $custom = get_post_custom(); echo $custom["p30-length"][0]; break; case "p30_speakers": $speakers = get_the_terms(0, "speaker"); if($speakers){ $speakers_html = array(); foreach ($speakers as $speaker) array_push($speakers_html, '' . $speaker->name . ''); echo implode($speakers_html, ", "); } break; } } // Template selection function template_redirect() { global $wp; if ($wp->query_vars["post_type"] == "podcast") { include(dirname (__FILE__) ."/podcast.php"); die(); } } // When a post is inserted or updated function wp_insert_post($post_id, $post = null) { if ($post->post_type == "podcast") { // Loop through the POST data foreach ($this->meta_fields as $key) { $value = @$_POST[$key]; if (empty($value)) { delete_post_meta($post_id, $key); continue; } // If value is a string it should be unique if (!is_array($value)) { // Update meta if (!update_post_meta($post_id, $key, $value)) { // Or add the meta data add_post_meta($post_id, $key, $value); } } else { // If passed along is an array, we should remove all previous data delete_post_meta($post_id, $key); // Loop through the array adding new values to the post meta as different entries with the same name foreach ($value as $entry) add_post_meta($post_id, $key, $entry); } } } } function admin_init() { // Custom meta boxes for the edit podcast screen add_meta_box("p30-meta", "Podcast Options", array(&$this, "meta_options"), "podcast", "side", "low"); } // Admin post meta contents function meta_options() { global $post; $custom = get_post_custom($post->ID); $length = $custom["p30-length"][0]; ?>