Advertisement
WebBox

Update MAP field with lat,lng,zoom

Dec 23rd, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | Source Code | 0 0
  1. <?php
  2.  
  3. function add_custom_query_var( $vars ){
  4.     $vars[] = "save_all_posts";
  5.     return $vars;
  6. }
  7. add_filter( 'query_vars', 'add_custom_query_var' );
  8.  
  9. function trigger_save_all_posts() {
  10.     if (intval(get_query_var('save_all_posts')) === 1) {
  11.         $args = array(
  12.             'post_type'      => 'restoran', // your post type
  13.             'post_status'    => 'publish',
  14.             'posts_per_page' => -1,
  15.         );
  16.  
  17.         $all_posts = get_posts($args);
  18.  
  19.         foreach ($all_posts as $post) {
  20.             $latitude = get_post_meta($post->ID, 'latitude', true); // latitude field
  21.             $longitude = get_post_meta($post->ID, 'longitude', true); // longitude field
  22.             $zoom = "14"; // zoom
  23.             $location_string = $latitude . ',' . $longitude . ',' . $zoom;
  24.             update_post_meta($post->ID, 'map',$location_string); // map field
  25.             echo '* ';
  26.         }
  27.  
  28.         exit;
  29.     }
  30. }
  31. add_action( 'template_redirect', 'trigger_save_all_posts' );
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement