我正在尝试通过 wp_remote_get 遍历我的所有帖子并更新和ID属性。看起来似乎并没有真正提出请求。它在localhost上,我看不到任何命中我的本地服务器。我错过了一些关于 wp_remote_get 是非阻塞的东西还是类似的东西?这是我的功能:
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 :(得分:0)
嗯,事实证明,wordpress没有在本地运行,它在不同的服务器上运行。因此,localhost实际上是wordpress实例的服务器。