2017-08-29 39 views
0

我想通過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>"; 
    } 

任何幫助將不勝感激。謝謝!

回答

0

好吧,事實證明,wordpress並沒有在本地運行,而是在不同的服務器上運行。因此,localhost實際上是wordpress實例的服務器。