__('Organizations'), 'singular_label' => __('Organization'), '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" => "org"), // Permalinks format 'supports' => array('title', 'editor', 'thumbnail') ); register_post_type( 'org' , $args ); register_taxonomy( 'mtype', 'org', array ('hierarchical' => false, 'label' => __('Museum Types'), 'singular_label' => __('Museum Type'), 'query_var' => 'mtype') ); add_new_rules('org'); // create PROJECTS $args = array( 'label' => __('Projects'), 'singular_label' => __('Project'), '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" => "proj"), // Permalinks format 'supports' => array('title', 'editor', 'thumbnail') ); register_post_type( 'proj' , $args ); register_taxonomy( 'ptype', 'proj', array ('hierarchical' => false, 'label' => __('Project Types'), 'singular_label' => __('Project Type'), 'query_var' => 'ptype') ); add_new_rules('proj'); // create EVENTS $args = array( 'label' => __('Events'), 'singular_label' => __('Event'), '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" => "event"), // Permalinks format 'supports' => array('title', 'editor', 'thumbnail') ); register_post_type( 'event' , $args ); // set up URL redirects add_new_rules('event'); // set up redirects add_action("template_redirect", 'midea_template_redirect'); } function add_new_rules($ptype){ global $wp_rewrite; $rewrite_rules = $wp_rewrite->generate_rewrite_rules("$ptype/"); $rewrite_rules["$ptype/?$"] = 'index.php?paged=1'; foreach($rewrite_rules as $regex => $redirect) { if(strpos($redirect, 'attachment=') === false) { $redirect .= "&post_type=$ptype"; } if(0 < preg_match_all('@\$([0-9])@', $redirect, $matches)) { for($i = 0; $i < count($matches[0]); $i++) { $redirect = str_replace($matches[0][$i], '$matches['.$matches[1][$i].']', $redirect); } } $wp_rewrite->add_rule($regex, $redirect, 'top'); } } function midea_template_redirect() { global $wp; $midea_custom_types = array('proj', 'org', 'event'); if (in_array($wp->query_vars["post_type"], $midea_custom_types)) { if ( is_robots() ) : do_action('do_robots'); return; elseif ( is_feed() ) : do_feed(); return; elseif ( is_trackback() ) : include( ABSPATH . 'wp-trackback.php' ); return; elseif($wp->query_vars["name"]): include(TEMPLATEPATH . "/../midea/single-".$wp->query_vars["post_type"].".php"); die(); else: include(TEMPLATEPATH . "/../midea/".$wp->query_vars["post_type"].".php"); die(); endif; } } ?>