__('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') ); // set up dashboard editing view add_action("manage_posts_custom_column", "org_custom_columns"); add_filter("manage_edit-org_columns", "org_columns"); 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_action("manage_posts_custom_column", "proj_custom_columns"); add_filter("manage_edit-proj_columns", "proj_columns"); 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 dashboard editing view add_action("manage_posts_custom_column", "event_custom_columns"); add_filter("manage_edit-event_columns", "event_columns"); // set up URL redirects add_new_rules('event'); // ser 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_org_fields() { // provide array of names for fields in organization content type; // init with empty valyes to fill later return array('web' => '', 'facebook' => '', 'twitter' => '' , 'address' => '', 'lat' => '', 'long' => '', 'tagline' => ''); } function midea_proj_fields() { // provide array of names for fields in project content type; // init with empty valyes to fill later return array('url' => '', 'org' => '', 'rating' => ''); } function midea_event_fields() { // provide array of names for fields in event content type; // init with empty valyes to fill later return array('start' => '', 'end' => '', 'url' => '', 'location' => ''); } function midea_admin_init() { // Custom meta boxes for the custom post types add_meta_box("org-meta", "MIDEA Organization Details", midea_org_options, 'org', 'normal', 'low'); add_meta_box("proj-meta", "MIDEA Project Details", midea_proj_options, 'proj', 'normal', 'low'); add_meta_box("event-meta", "MIDEA Event Details", midea_event_options, 'event', 'normal', 'low'); } function midea_org_options() { // add meta data fields for a MIDEA organization content type global $post; // Use nonce for verification echo ''; $my_fields = midea_org_fields(); // fields for this content type foreach ($my_fields as $key => $value) { // load values into our array $my_fields[$key] = get_post_meta($post->ID, 'midea-org-' . $key, true); } echo '
About
A one sentence blurb that describes what this organization is about:
Online Presence
:
:
:
Location
:
: ' . "\n"; echo ': ' . "\n"; } function midea_get_orgs() { // set up query to get all orgs $my_query = 'post_type=org&post_status=publish&orderby=title&order=ASC&posts_per_page=-1'; $getOrgs = new WP_Query(); $getOrgs->query($my_query); // put 'em in dis array $all_orgs = array(); while ($getOrgs->have_posts()) : $getOrgs->the_post(); $id = get_the_ID(); $all_orgs[$id] = get_the_title($id); endwhile; return($all_orgs); } function midea_get_event_str($start, $end) { // format start and end dates based on UNIX time parameters // blank data if ($start == "" or $end == "") return ""; $date_format = "F j, Y"; $time_format = "h:i a"; $start=(int)$start; $end=(int)$end; $my_date_start = date($date_format, $start); $my_date_end = date($date_format, $end); if ($my_date_start == $my_date_end) { // one day event $out = $my_date_start; if (date("i:s", $start) != "12:00") { $out .= ' ' . date($time_format, $start) . ' - ' . date($time_format, $end) . ' (PT)'; } } else { if (date('M', $start) == date('M', $end) ) { // event starts and ends in same month $out = date('F j', $start) . '-' . date('j, Y', $end); } else { // event crosses month boundary, let's hope we dont have any that cross years! $out = date('F j', $start) . ' - ' . date('F j, Y', $end); } } return ($out); } function midea_get_project_info($id) { $my_proj_fields = midea_proj_fields(); // fields for this content type foreach ($my_proj_fields as $key => $value) { // load values into our array $my_proj_fields[$key] = get_post_meta($id, 'midea-proj-' . $key, true); } $my_proj_fields['orgname'] = ($my_proj_fields['org'] > 0) ? get_the_title((int)$my_proj_fields['org']) : 'MIDEA'; $my_proj_fields['id'] = $id; return ($my_proj_fields); } function midea_get_event_info($id) { $my_event_fields = midea_event_fields(); // fields for this content type foreach ($my_event_fields as $key => $value) { // load values into our array $my_event_fields[$key] = get_post_meta($id, 'midea-event-' . $key, true); } $my_event_fields['date_str'] = midea_get_event_str($my_event_fields['start'] , $my_event_fields['end']); $my_event_fields['id'] = $id; return ($my_event_fields); } function midea_proj_options() { // add meta data fields for a MIDEA organization content type global $post; // Use nonce for verification echo ''; $my_fields = midea_proj_fields(); // fields for this content type foreach ($my_fields as $key => $value) { // load values into our array $my_fields[$key] = get_post_meta($post->ID, 'midea-proj-' . $key, true); } $all_orgs = midea_get_orgs(); echo '
:
:
:
:
:
Date(s) Event dates (PST). If all day, omit time. For one day events use same start and end date. Enter as text like "Feb 21, 2010" or "Jun 29, 2010 8:00 am"
' . "\n" . '