Skip to content

Instantly share code, notes, and snippets.

@eduardo-g-silva
Created December 9, 2014 18:31
Show Gist options
  • Save eduardo-g-silva/d4d2fa248020ffd8ab2a to your computer and use it in GitHub Desktop.
Save eduardo-g-silva/d4d2fa248020ffd8ab2a to your computer and use it in GitHub Desktop.
// the code it is very simple:
// first get the table with the data and then use the wp
// update_post_meta with update the value base on the post id
// and wp_set_object_terms to change the custom categories
// with true at the end to append the category without delete the existing.
add_shortcode('myFunction', update_geolocation');
function update_geolocation() {
$sql = "select Post_id, Lat, Lon from tblGeodatawithposts";
global $wpdb;
$rows = $wpdb->get_results($sql, ARRAY_N);
$counter = 0;
foreach ($rows as $row) {
$counter ++;
$data = get_post_meta($row[0], '_ait-dir-item');
$data[0]['gpsLatitude'] = $row[1];
$data[0]['gpsLongitude'] = $row[2];
update_post_meta($row[0], '_ait-dir-item', $data[0]);
wp_set_object_terms( $row[0], 400, 'ait-dir-item-category', true );
}
return $counter . " records updated...";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment