function cp_add_new_listing($advals) { global $wpdb; $new_tags = ''; $ad_length = ''; $attach_id = ''; $the_attachment = ''; // tags are tricky and need to be put into an array before saving the ad if (!empty($advals['tags_input'])) { $new_tags = explode(',', $advals['tags_input']); } // put all the new ad elements into an array // these are the minimum required fields for WP (except tags) $new_ad = array(); $new_ad['post_title'] = appthemes_filter($advals['post_title']); $new_ad['post_content'] = trim($advals['post_content']); $new_ad['post_status'] = 'pending'; // no longer setting final status until after images are set $new_ad['post_author'] = 0; if (!empty($_SESSION['anonym']) && $_SESSION['anonym'] != '') { $new_ad['post_author'] = 0; } else { $new_ad['post_author'] = $advals['user_id']; } $new_ad['post_type'] = APP_POST_TYPE; // make sure the WP sanitize_post function doesn't strip out embed & other html if (get_option('cp_allow_html') == 'yes') { $new_ad['filter'] = true; } //print_r($new_ad).' <- new ad array<br>'; // insert the new ad $post_id = wp_insert_post($new_ad); //set the custom post type categories wp_set_post_terms($post_id, appthemes_filter($advals['cat']), APP_TAX_CAT, false); //set the custom post type tags wp_set_post_terms($post_id, $new_tags, APP_TAX_TAG, false); //$location = get_field('location'); //**************************************EKLEME********************************************** // Google Maps ten Pozisyon Seçilmiþse O pozisyonu kaydeder seçimemiþse adresten bulur if (!empty($_SESSION['kordinat']) && $_SESSION['kordinat'] != '') { $category = get_the_terms($post_id, 'ad_cat'); $address1 = explode('|', $_SESSION['kordinat']); $address2 = explode(',', $address1[1]); cp_add_geocode($post_id, $category[0]->name, $address2[0], $address2[1]); $_SESSION['kordinat'] = ''; } else { $_SESSION['kordinat'] == 'yok'; } //************************************************************************************ // the unique order ID we created becomes the ad confirmation ID // we will use this for payment systems and for activating the ad // later if need be. it needs to start with cp_ otherwise it won't // be loaded in with the ad so let's give it a new name $advals['cp_sys_ad_conf_id'] = $advals['oid']; // get the ad duration and first see if ad packs are being used // if so, get the length of time in days otherwise use the default // prune period defined on the CP settings page if (isset($advals['pack_duration'])) { $ad_length = $advals['pack_duration']; } else { $ad_length = get_option('cp_prun_period'); } // set the ad listing expiration date and put into a session $ad_expire_date = date_i18n('m/d/Y H:i:s', strtotime('+' . $ad_length . ' days')); // don't localize the word 'days' $advals['cp_sys_expire_date'] = $ad_expire_date; $advals['cp_sys_ad_duration'] = $ad_length; // now add all the custom fields into WP post meta fields foreach ($advals as $meta_key => $meta_value) { if (appthemes_str_starts_with($meta_key, 'cp_') && !is_array($advals[$meta_key])) { add_post_meta($post_id, $meta_key, $meta_value, true); } if (appthemes_str_starts_with($meta_key, 'cp_') && is_array($advals[$meta_key])) { foreach ($advals[$meta_key] as $checkbox_value) { add_post_meta($post_id, $meta_key, $checkbox_value); } } } // if they checked the box for a featured ad, then make the post sticky if (isset($advals['featured_ad'])) { stick_post($post_id); } if (isset($advals['attachment'])) { $the_attachment = $advals['attachment']; // associate the already uploaded images to the new ad and create multiple image sizes $attach_id = cp_associate_images($post_id, $the_attachment, true); } // set the thumbnail pic on the WP post //cp_set_ad_thumbnail($post_id, $attach_id); //last step is to publish the ad when its appropriate to publish immediately $final_status = cp_set_post_status($advals); if ($final_status == 'publish') { $final_post = array(); $final_post['ID'] = $post_id; $final_post['post_status'] = $final_status; $update_result = wp_update_post($final_post); } // kick back the post id in case we want to use it return $post_id; }
function cp_update_geocode($post_id, $cat, $lat, $lng) { global $wpdb; if (!$lat || !$lng || !$cat || !$post_id) { return false; } $post_id = absint($post_id); if (!cp_get_geocode($post_id, $cat)) { return cp_add_geocode($post_id, $cat, $lat, $lng); } $lat = floatval($lat); $lng = floatval($lng); $wpdb->update($wpdb->cp_ad_geocodes, array('lat' => $lat, 'lng' => $lng), array('post_id' => $post_id, 'category' => $cat)); return true; }
function cp_update_geocode($post_id, $cat, $lat, $lng) { global $wpdb; if (!empty($cat)) { _deprecated_argument(__FUNCTION__, '3.3.2'); } if (!$lat || !$lng || !$post_id) { return false; } $post_id = absint($post_id); if (!cp_get_geocode($post_id)) { return cp_add_geocode($post_id, '', $lat, $lng); } $lat = floatval($lat); $lng = floatval($lng); $wpdb->update($wpdb->cp_ad_geocodes, array('lat' => $lat, 'lng' => $lng), array('post_id' => $post_id)); return true; }
function cp_update_geocode($post_id, $cat, $lat, $lng) { global $wpdb; if (!$lat || !$lng || !$cat || !$post_id) { return false; } $post_id = absint($post_id); $table = $wpdb->prefix . 'cp_ad_geocodes'; if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$table} WHERE post_id = %d AND category = %s", $post_id, $cat))) { return cp_add_geocode($post_id, $cat, $lat, $lng); } $lat = floatval($lat); $lng = floatval($lng); $wpdb->update($table, array('lat' => $lat, 'lng' => $lng), array('post_id' => $post_id, 'category' => $cat)); return true; }