/** * Saves the posts into WordPress * * @param array|object $post */ public function posts($post) { /* * TODO: If this isn't an array it probably is an error message, need to handle it */ if (is_array($post)) { //get post data $property_formatted = array(); //loop through properties found foreach ($post as $property) { //reassign fields to ones that look good $property_formatted['property_price'] = $property['Lp_dol']; $property_formatted['mls'] = $property['Ml_num']; $property_formatted['address'] = $property['Addr']; $property_formatted['bathrooms'] = $property['Bath_tot']; $property_formatted['bedrooms'] = $property['Br']; $property_formatted['province'] = $property['County']; $property_formatted['broker'] = $property['Rltr']; $property_formatted['rooms'] = $property['Rms']; $property_formatted['rentorsale'] = $property['S_r']; $property_formatted['status'] = $property['Status']; $property_formatted['postal_code'] = $property['Zip']; $property_formatted['city'] = $property['Area']; $property_formatted['last_updated_text'] = $property['Timestamp_sql']; $property_formatted['last_updated_photos'] = $property['Pix_updt']; $property_formatted['description'] = $property['Ad_text']; $property_formatted['property_area'] = $property['Sqft']; $property_formatted['full_dump'] = $property; $update_check = ''; //This will check for old properties and see if they need to be updated $update_check = CheckOld::data($property_formatted['address'], $property_formatted['last_updated_text'], $property_formatted['status']); if (is_array($update_check)) { if (isset($update_check['update'])) { $update = new Update($property_formatted['mls'], $update_check['update'], get_post_meta($update_check['update'], 'wptrebs_photos', true)); $update->posts($property); } elseif (isset($update_check['new'])) { //set up arguments before entering post to wp $post_args = array('post_title' => $property_formatted['address'], 'post_content' => $property_formatted['description'], 'post_status' => 'publish', 'post_type' => 'property'); //insert post and return new post id $posted_property = wp_insert_post($post_args); //add post meta using the new post id and good looking array foreach ($property_formatted as $key => $value) { if (!empty($value)) { add_post_meta($posted_property, $key, $value, true) || update_post_meta($posted_property, $key, $value); } } $photos = $this->feed->photos($property_formatted['mls']); //Get the photos self::photos($photos, $posted_property, $property_formatted['mls']); } } } } }