Created
December 9, 2014 18:31
-
-
Save eduardo-g-silva/d4d2fa248020ffd8ab2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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