简体   繁体   English

wp_remote_get不在while循环中被调用

[英]wp_remote_get not getting called in while loop

I'm trying to iterate over all of my posts and update and ID attribute via wp_remote_get . 我正在尝试遍历我的所有帖子,并通过wp_remote_get更新和ID属性。 It doesn't seem like the request is actually being made. 似乎请求实际上并未发出。 It's on localhost and I see nothing hitting my local server. 它在localhost上,我什么也看不到本地服务器。 Am I missing something about wp_remote_get being non-blocking or something like that? 我是否缺少关于wp_remote_get的非阻塞性信息或类似信息? Here is my function: 这是我的功能:

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

Any help would be much appreciated. 任何帮助将非常感激。 Thanks! 谢谢!

Well, as it turns out, wordpress wasn't running locally it was running on a different server. 事实证明,wordpress不在本地运行,而是在其他服务器上运行。 Therefore, localhost was actually the server of the wordpress instance. 因此,本地主机实际上是wordpress实例的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM