Php update_post_meta和update_字段在未收到任何错误的情况下不工作

Php update_post_meta和update_字段在未收到任何错误的情况下不工作,php,wordpress,api,insert-update,Php,Wordpress,Api,Insert Update,我正在使用一个wordpress站点,该站点通过cron作业自动将所有数据从API导入该站点。但是,我现在要从API保存字段数据。问题是update\u post\u meta和update\u字段都不起作用 我已经尝试过在这两种储蓄方法之间进行互换,但都不起作用。没有错误提示,也没有结果(这对我来说很奇怪)。我检查了该网站的内置插件,它使用了update\u post\u meta add_action('wp_ajax_nopriv_get_properties_from_api','get

我正在使用一个wordpress站点,该站点通过cron作业自动将所有数据从API导入该站点。但是,我现在要从API保存字段数据。问题是update\u post\u meta和update\u字段都不起作用

我已经尝试过在这两种储蓄方法之间进行互换,但都不起作用。没有错误提示,也没有结果(这对我来说很奇怪)。我检查了该网站的内置插件,它使用了update\u post\u meta

add_action('wp_ajax_nopriv_get_properties_from_api','get_properties_from_api');
add_action('wp_ajax_get_properties_from_api','get_properties_from_api')
    function  get_properties_from_api(){

        $file = get_stylesheet_directory() . '/report.txt';
        $current_page=(! empty($_POST['current_page'])) ? $_POST['current_page'] : 1;
        $properties = [];

        $results = wp_remote_retrieve_body(wp_remote_get('https://www.realestateview.com.au/listing_api?rm=search&company=castlemain&code=29GKRRSgkVdQVM&CID=5813&json=1&ptr=r&con=S&portalview=residential&rn=1&pg='. $current_page));

        file_put_contents($file, "Current page: ". $current_page. "\n\n", FILE_APPEND);

        $results=json_decode($results, true);

        if(!is_array($results['Listings']) || empty($results['Listings'])){
            return false;
        }

        $properties[]=$results;
        foreach($properties[0] as $property){
            $property_slug = sanitize_title($property->TitleNoHTML, '-', $property->OrderID);

            $inserted_property = wp_insert_post([
                'post_name' => $property_slug,
                'post_title' => $property->TitleNoHTML,
                'post_type' => 'property', 
                'post_status' => 'publish',
            ]);

            if(is_wp_error($inserted_property)){
                continue;
            }
            $fillable=[
            //Basic information
            get_the_title($inserted_property) => 'TitleNoHTML',
            'REAL_HOMES_property_price'  => 'PriceText',
            'REAL_HOMES_property_size' => 'LandSizeText',
            'REAL_HOMES_property_bedrooms' => 'BedroomsCount',
            'REAL_HOMES_property_bathrooms' => 'BathroomsCount',
            'REAL_HOMES_property_garage' => 'LockUpGaragesCount',
            'REAL_HOMES_featured' => 'FeaturedProperty',
            //$this->REAL_HOMES_property_id = 
            //$this->REAL_HOMES_property_year_built =

            //Location on Map
            'REAL_HOMES_property_address' => 'AddressText',
            'REAL_HOMES_property_location' => 'Suburb',
            'REAL_HOMES_property_map' => 'DisplayTrueAddress',

            //Gallery
            'REAL_HOMES_property_images' => 'PhotoOriginalURL',

            //Floor Plans

            //$this->inspiry_floor_plan_name =
            'inspiry_floor_plan_price' => 'PriceText',
            //$this->inspiry_floor_plan_price_postfix =
            // $this->inspiry_floor_plan_size =
            // $this->inspiry_floor_plan_size_postfix = 
            'inspiry_floor_plan_bedrooms' => 'BedroomsCount',
            'inspiry_floor_plan_bathrooms' =>'BathroomsCount',
            // $this->inspiry_floor_plan_descr = 
            'inspiry_floor_plan_image' => 'FloorplanThumbURL',

            //Property Video
            'inspiry_video_group_image' => 'PhotoThumbURL',
            //$this->inspiry_video_group_title = 
            'inspiry_video_group_url' => 'VideoURL',

            //DEPRECATED FIELDS
            // $this->REAL_HOMES_360_virtual_tour =
            // $this->REAL_HOMES_tour_video_url_divider =
            // $this->REAL_HOMES_tour_video_url =
            // $this->REAL_HOMES_tour_video_image =

            //Agent
            //$this->REAL_HOMES_agent_display_option =
            'REAL_HOMES_agents' => 'ContactAgentName',

            //Energy Performance
            // $this->REAL_HOMES_energy_class  =
            // $this->REAL_HOMES_energy_performance =
            // $this->REAL_HOMES_epc_current_rating =
            // $this->REAL_HOMES_epc_potential_rating =

            //Misc
            // $this->REAL_HOMES_sticky =
            // $this->inspiry_property_label =
            // $this->inspiry_property_label_color =

            // $this->REAL_HOMES_attachments =

            'inspiry_property_owner_name' => 'ClientName',
            //$this->inspiry_property_owner_contact = 
            'inspiry_property_owner_address' => 'ClientAddress',
            // $this->REAL_HOMES_property_private_note =
            // $this->inspiry_message_to_reviewer =

            //Homepage slider
            // $this->REAL_HOMES_add_in_slider = 
            // $this->REAL_HOMES_slider_image =
            // $this->REAL_HOMES_page_banner_image =

            //Additional fields
            'inspiry_InspectionDateandStartTime' => 'ISOInspectionStart',
            'inspiry_InspectionDateandFinishTime' => 'ISOInspectionFinish',             
            ];
            foreach($fillable as $key => $TitleNoHTML){
                update_post_meta($inserted_property, $key, $property->$TitleNoHTML);

            }
        }


        $current_page = $current_page + 1;
        wp_remote_post(admin_url('admin-ajax.php?action=get_properties_from_api'), [
            'blocking' => false,
            'sslverify' => false,
            'body' => [
                'current_page' => $current_page
            ]
        ]);

What I'm already expecting is it should be already save some data, if not, it should produce an error but for some weird reason, there isn't. I tried to var_dump some variables and I think it should be working. Would anyone be able to help me find out where I gone wrong?

为了用真正的cron作业替换Wordpress cron,您需要设置一个cron作业,该作业将使用
wget
从网页获取数据。首先,您需要创建一个
Wordpress
页面,其中包含
PHP
代码,然后使用
wget
使用cron获取内容

真正的cron作业命令如下所示:

wget-q-O-http://yourdomain.com/your_cron_page >/dev/null 2>&1

-q
告诉
wget
安静运行(即不输出通常的状态信息)

-O/dev/null
告诉它输出到
/dev/null


请记住,每个人都可以访问此页面,因此您可能需要设置一些限制。

这是一个真正的cron还是一个执行cron的插件?一个真正的cron作业不会知道wordpress函数,你需要使用
wget
而不是运行php脚本。你能给我指点一下我怎样才能做到吗?我是wordpress的新手,这项任务非常令人紧张,这是否意味着我正在尝试的工作可以通过默认的wordpress cron作业来完成?默认的一个可以更新或添加自定义字段的信息吗?是的,有几个插件可以这样做,或者将您的cron链接到
wp cron.php
。更多信息请点击此处: