wp_remote_get在while循环中没有被调用

wp_remote_get在while循环中没有被调用

问题描述:

我想通过wp_remote_get遍历我的所有帖子,更新和ID属性。它似乎并没有真正提出要求。它在本地主机上,我看不到任何东西打到我的本地服务器。我错过了什么wp_remote_get是非阻塞或类似的东西?这里是我的功能:wp_remote_get在while循环中没有被调用

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>"; 
    } 

任何帮助将不胜感激。谢谢!

好吧,事实证明,wordpress并没有在本地运行,而是在不同的服务器上运行。因此,localhost实际上是wordpress实例的服务器。