Geolocalizar listados en masa después de importarlos
Paso 1:
Verifica que la API de Google Maps esté funcionando correctamente.
Paso 2:
Asegúrate de que hayas importado la ubicación o dirección de forma correcta en los listados.
Paso 3:
Instala y activa el tema hijo de MyListing. Luego, ve a Apariencia > Editor > functions.php y añade el fragmento de código proporcionado después de la línea // happy coding.
Paso 4:
En la Consola de Google Cloud, configura temporalmente las restricciones de tu clave de API como “Ninguna”.
Paso 5:
Visita la siguiente URL en tu navegador:tusitio.com/?geolocate_listings=1
Esto geolocalizará todos los listados y estos aparecerán en el mapa de la página de exploración.
| <?php |
| add_action( ‘init’, function() { |
| if ( empty( $_GET[‘geolocate_listings’] ) || ! current_user_can( ‘administrator’ ) ) { |
| return; |
| } |
| $next_data = 50; |
| $offset = 0; |
| do { |
| $listings = (array) get_posts( [ |
| ‘post_type’ => ‘job_listing’, |
| ‘offset’ => $offset, |
| ‘posts_per_page’ => $next_data, |
| ‘post_status’ => [‘publish’, ‘private’, ‘expired’], |
| ‘meta_query’ => [ |
| ‘relation’ => ‘OR’, |
| [ ‘key’ => ‘geolocation_lat’, ‘value’ => » ], |
| [ ‘key’ => ‘geolocation_long’, ‘value’ => » ], |
| [ ‘key’ => ‘geolocation_lat’, ‘compare’ => ‘NOT EXISTS’ ], |
| [ ‘key’ => ‘geolocation_long’, ‘compare’ => ‘NOT EXISTS’ ], |
| ], |
| ] ); |
| printf( |
| «Fetching geolocation data from listing %d to %d <br />», |
| $offset + 1, |
| $offset + $next_data |
| ); |
| flush(); |
| ob_flush(); |
| foreach ( $listings as $listing ) { |
| if ( ! ( $location = get_post_meta( $listing->ID, ‘_job_location’, true ) ) ) { |
| printf( ‘<p style=»color: #8e8e8e;»>Skipping geolocation for listing #%d (missing address)</p>’, $listing->ID ); |
| continue; |
| } |
| $geocoded = mylisting()->geocoder()->save_location( $listing->ID, $location ); |
| if ( $geocoded !== false ) { |
| printf( ‘<p style=»color: green;»>Geolocation successful for listing #%d (%s)</p>’, $listing->ID, $location ); |
| continue; |
| } |
| printf( ‘<p style=»color: red;»>Failed to geolocate listing #%d (%s)</p>’, $listing->ID, $location ); |
| } |
| $offset = ( ! $offset ) ? $next_data : $offset + $next_data; |
| } while( ! empty( $listings ) ); |
| exit(‘All listings are updated, you can close this window.’); |
| }, 250 ); |
Soporte
Usa el buscador de temas y encuentra lo que necesitas
¿Aún no lo encuentras?
Contacta al servicio de soporte

