Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Last active January 9, 2020 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remcotolsma/50c9999b3c1a36d5cc98d47473d7f937 to your computer and use it in GitHub Desktop.
Save remcotolsma/50c9999b3c1a36d5cc98d47473d7f937 to your computer and use it in GitHub Desktop.
Geocode providers.
<?php
define( 'WP_USE_THEMES', false );
require './wp-blog-header.php';
$query = new WP_Query(
array(
'post_type' => 'provider',
'nopaging' => true,
)
);
$number = 0;
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$post_id = get_the_ID();
$address = get_post_meta( $post_id, '_pronamic_google_maps_address', true );
echo $post_id, ' - ', get_the_title(), ' - ', $address, '<br />';
if ( empty( $address ) ) {
$street = get_post_meta( $post_id, 'coopdichtbij_provider_address', true );
$postal_code = get_post_meta( $post_id, 'coopdichtbij_provider_postal_code', true );
$city = get_post_meta( $post_id, 'coopdichtbij_provider_city', true );
$address .= $street . "\r\n";
$address .= $postal_code . ' ' . $city;
$address = trim( $address );
echo 'Address: ', $address, '<br />';
if ( ! empty( $address ) ) {
update_post_meta( $post_id, '_pronamic_google_maps_address', $address );
$number++;
}
}
$active = get_post_meta( $post_id, '_pronamic_google_maps_active', true );
$geocode_status = get_post_meta( $post_id, '_pronamic_google_maps_geocode_status', true );
if ( empty( $active ) && 'OK' === $geocode_status ) {
update_post_meta( $post_id, '_pronamic_google_maps_active', 'true' );
}
}
}
echo '<br />';
echo 'Number: ', $number;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment