コード例 #1
0
ファイル: template-tags.php プロジェクト: hypenotic/slowfood
 /**
  * Returns a list of lectures that are associated with this event
  *
  * @param int optional post id
  * @return mixed array of posts or false
  */
 function the_event_lectures($postId = null)
 {
     if ($postId === null || !is_numeric($postId)) {
         global $post;
         $postId = $post->ID;
     }
     if (!is_event($postId)) {
         return false;
     }
     global $wpdb;
     $query = "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = '_lectureEvent' AND meta_value = '{$postId}'";
     $results = $wpdb->get_results($query);
     if (empty($results)) {
         return $results;
     }
     $lectures = array();
     foreach ($results as $lecture) {
         $lectures[] = $lecture->post_id;
     }
     $lectures = array_unique($lectures);
     $results = array();
     foreach ($lectures as $lectureId) {
         $results[] = get_post($lectureId);
     }
     return $results;
 }
コード例 #2
0
 /**
  * Adds / removes the event details as meta tags to the post.
  *
  * @param string $postId 
  * @return void
  */
 public function addEventMeta($postId)
 {
     if ($_POST['isEvent'] == 'yes') {
         $category_id = $this->create_category_if_not_exists();
         // add a function below to remove all existing categories - wp_set_post_categories(int ,  array )
         if ($_POST['EventAllDay'] == 'yes') {
             $_POST['EventStartDate'] = $this->dateToTimeStamp($_POST['EventStartYear'], $_POST['EventStartMonth'], $_POST['EventStartDay'], "12", "00", "AM");
             $_POST['EventEndDate'] = $this->dateToTimeStamp($_POST['EventEndYear'], $_POST['EventEndMonth'], $_POST['EventEndDay'], "11", "59", "PM");
         } else {
             delete_post_meta($postId, '_EventAllDay');
             $_POST['EventStartDate'] = $this->dateToTimeStamp($_POST['EventStartYear'], $_POST['EventStartMonth'], $_POST['EventStartDay'], $_POST['EventStartHour'], $_POST['EventStartMinute'], $_POST['EventStartMeridian']);
             $_POST['EventEndDate'] = $this->dateToTimeStamp($_POST['EventEndYear'], $_POST['EventEndMonth'], $_POST['EventEndDay'], $_POST['EventEndHour'], $_POST['EventEndMinute'], $_POST['EventEndMeridian']);
         }
         // sanity check that start date < end date
         $startTimestamp = strtotime($_POST['EventStartDate']);
         $endTimestamp = strtotime($_POST['EventEndDate']);
         if ($startTimestamp > $endTimestamp) {
             $_POST['EventEndDate'] = $_POST['EventStartDate'];
         }
         // make state and province mutually exclusive
         if ($_POST['EventStateExists']) {
             $_POST['EventProvince'] = '';
         } else {
             $_POST['EventState'] = '';
         }
         //ignore Select a Country: as a country
         if ($_POST['EventCountryLabel'] == "") {
             $_POST['EventCountry'] = "";
         }
         //google map checkboxes
         if (!isset($_POST['EventShowMapLink'])) {
             update_post_meta($postId, '_EventShowMapLink', 'false');
         }
         if (!isset($_POST['EventShowMap'])) {
             update_post_meta($postId, '_EventShowMap', 'false');
         }
         // give add-on plugins a chance to cancel this meta update
         try {
             do_action('sp_events_event_save', $postId);
             if (!$this->postExceptionThrown) {
                 delete_post_meta($postId, self::EVENTSERROROPT);
             }
         } catch (TEC_Post_Exception $e) {
             $this->postExceptionThrown = true;
             update_post_meta($postId, self::EVENTSERROROPT, trim($e->getMessage()));
         }
         //update meta fields
         foreach ($this->metaTags as $tag) {
             $htmlElement = ltrim($tag, '_');
             if ($tag != self::EVENTSERROROPT) {
                 if (isset($_POST[$htmlElement])) {
                     if (is_string($_POST[$htmlElement])) {
                         $_POST[$htmlElement] = filter_var($_POST[$htmlElement], FILTER_SANITIZE_STRING);
                     }
                     update_post_meta($postId, $tag, $_POST[$htmlElement]);
                 }
             }
         }
         try {
             do_action('sp_events_update_meta', $postId);
             if (!$this->postExceptionThrown) {
                 delete_post_meta($postId, self::EVENTSERROROPT);
             }
         } catch (TEC_Post_Exception $e) {
             $this->postExceptionThrown = true;
             update_post_meta($postId, self::EVENTSERROROPT, trim($e->getMessage()));
         }
         update_post_meta($postId, '_EventCost', the_event_cost($postId));
         // XXX eventbrite cost field
         // merge event category into this post
         $cats = wp_get_object_terms($postId, 'category', array('fields' => 'ids'));
         $new_cats = array_merge(array(get_category($category_id)->cat_ID), $cats);
         wp_set_post_categories($postId, $new_cats);
     }
     if ($_POST['isEvent'] == 'no' && is_event($postId)) {
         // remove event meta tags if they exist...this post is no longer an event
         foreach ($this->metaTags as $tag) {
             delete_post_meta($postId, $tag);
         }
         $event_cats[] = $this->eventCategory();
         $cats = get_categories('child_of=' . $this->eventCategory());
         foreach ($cats as $cat) {
             $event_cats[] = $cat->term_id;
         }
         // remove the event categories from this post but keep any non-event categories
         $terms = wp_get_object_terms($postId, 'category');
         $non_event_cats = array();
         foreach ($terms as $term) {
             if (!in_array($term->term_id, $event_cats)) {
                 $non_event_cats[] = $term->term_id;
             }
         }
         wp_set_post_categories($postId, $non_event_cats);
         try {
             do_action('sp_events_event_clear', $postId);
             if (!$this->postExceptionThrown) {
                 delete_post_meta($postId, self::EVENTSERROROPT);
             }
         } catch (TEC_Post_Exception $e) {
             $this->postExceptionThrown = true;
             update_post_meta($postId, self::EVENTSERROROPT, trim($e->getMessage()));
         }
     }
 }