2017-08-29 5 views
0

J'essaie de parcourir tous mes messages et mettre à jour et l'attribut ID via wp_remote_get. Il ne semble pas que la demande soit réellement faite. C'est sur localhost et je ne vois rien qui frappe mon serveur local. Ai-je manqué quelque chose à propos de wp_remote_get étant non-bloquant ou quelque chose comme ça? Voici ma fonction:wp_remote_get ne pas être appelé dans la boucle

function convert_to_postgres() { 
     $args = array(
      'post_type'=>'post', //whatever post type you need to update 
      'numberposts'=>-1 
     ); 

     $all_posts = get_posts($args); 

     foreach($all_posts as $post){ 
      echo get_the_title($post); 
      echo "<br>"; 

      if(have_rows('article_hotels', $post->ID)) { 
       while (have_rows('article_hotels', $post->ID)) : the_row(); 
        $legacy_id = get_sub_field('tripcraft_hotel_id')['id']; 
        $url = get_option('tripcraft_widgets_hotel_master_url') . "/wordpress/hotels/legacy_id/{$legacy_id}"; 
        $response = wp_remote_get($url); 
        $api_response = json_decode(wp_remote_retrieve_body($response), true); 
        echo get_sub_field('hotel_name'); 
        echo "<br>"; 
        echo "Legacy ID: " . $legacy_id; 
        echo "<br>"; 
        echo "New ID: " . $api_response; 
        echo "<br>"; 
       endwhile; 
       echo "<br>"; 
      } else { 
       echo "No hotels found"; 
       echo "<br>"; 
      } 
      echo "<br>"; 
     } 
     echo "<a href='options-general.php?page=plugin_hotel_id'>Back</a>"; 
    } 

Toute aide serait grandement appréciée. Merci!

Répondre

0

Eh bien, il se trouve que WordPress ne fonctionnait pas localement, il fonctionnait sur un serveur différent. Par conséquent, localhost était en fait le serveur de l'instance wordpress.