__('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:

'; echo '

Online Presence

:

' . "\n"; echo '

:

' . "\n"; echo '

:

' . "\n"; echo '

Location

:

' . "\n" . '

: ' . "\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 '

:

' . "\n"; echo '

:

'; echo '

:

'; } function midea_event_options() { // add meta data fields for a MIDEA event content type global $post; // Use nonce for verification echo ''; $my_fields = midea_event_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-event-' . $key, true); } // parse start date/time if ( $my_fields['start'] == '') { $my_start = ''; } else { // create date string $my_start = date("M d, Y", $my_fields['start']); //if time is set, format it and appemd if (date("h:i", $my_fields['start']) != '12:00') $my_start .= ' ' . date("h:i a", $my_fields['start']); } if ( $my_fields['end'] == '') { $my_end = ''; } else { // create date string $my_end = date("M d, Y", $my_fields['end']); //if time is set, format it and appemd if (date("h:i", $my_fields['end']) != '12:00') $my_end .= ' ' . date("h:i a", $my_fields['end']); } echo '

:

' . "\n"; echo '

:

' . "\n"; 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" . '

' . "\n" ; } // When a post is inserted or updated function midea_save_post() { global $post; $post_id = $post->ID; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['midea_noncename'], 'MyNonceCode')) return $post_id; // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want // to do anything if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; // flag to set if we need to deal with custom post type // not exactly sure if we need this, but it cannot hurt $post_flag = 'x'; if ($post->post_type == "org") { $my_fields = midea_org_fields(); // fields for this content type $post_flag = 'org'; } elseif ($post->post_type == "proj") { $my_fields = midea_proj_fields(); // fields for this content type $post_flag = 'proj'; } elseif ($post->post_type == "event") { $my_fields = midea_event_fields(); // fields for this content type $post_flag = 'event'; } if ($post_flag != 'x') { // we have MIDEA content to deal with // Loop through the MIDEA field data foreach ($my_fields as $k=>$v) { $key = 'midea-' . $post_flag . '-' . $k; $value = @$_POST[$key]; if (empty($value)) { delete_post_meta($post_id, $key); continue; } // special check for event time fields, convert as needed to unix time if ($key == 'midea-event-start' OR $key == 'midea-event-end' ) { $value = strtotime($value); } // 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 org_columns($columns) { $columns = array( "cb" => "", "title" => "Organization", "web" => "Web Site", "address" => "Address", "status" => "Status", ); return $columns; } function org_custom_columns($column) { global $post; if ("ID" == $column) echo $post->ID; elseif ("title" == $column) echo $post->post_title; elseif ("web" == $column) { $ourl = get_post_meta($post->ID, 'midea-org-web', true); echo '' . $ourl . ''; } elseif ("address" == $column) echo get_post_meta($post->ID, 'midea-org-address', true); elseif ("status" == $column) echo ucfirst($post->post_status) . 'ed
' . substr($post->post_date,0,10) ; } function proj_columns($columns) { $columns = array( "cb" => "", "title" => "Project", "org" => "Organization", "rating" => "Rating", "pstatus" => "Status", ); return $columns; } function proj_custom_columns($column) { global $post; if ("ID" == $column) echo $post->ID; elseif ("title" == $column) echo $post->post_title; elseif ("rating" == $column) echo get_post_meta($post->ID, 'midea-proj-rating', true); elseif ("org" == $column) { $oid = get_post_meta($post->ID, 'midea-proj-org', true); if ($oid > 0) echo get_the_title($oid); } elseif ("pstatus" == $column) echo ucfirst($post->post_status) . 'ed
' . substr($post->post_date,0,10) ; } function event_columns($columns) { $columns = array( "cb" => "", "title" => "Event", "when" => "Date", "location" => "Location", "estatus" => "Status", ); return $columns; } function event_custom_columns($column) { global $post; if ("ID" == $column) echo $post->ID; elseif ("title" == $column) echo $post->post_title; elseif ("location" == $column) echo get_post_meta($post->ID, 'midea-event-location', true); elseif ("when" == $column) echo midea_get_event_str( get_post_meta($post->ID, 'midea-event-start', true), get_post_meta($post->ID, 'midea-event-end', true) ); elseif ("estatus" == $column) echo ucfirst($post->post_status) . 'ed
' . substr($post->post_date,0,10) ; } 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; } } ?>