无法从json提取carouselURL导入帖子

时间:2019-05-26 13:33:52

标签: json wordpress object post

尝试从解码的json中获取图片网址,并将其添加到wordpres中的自定义字段中

我试图了解我是否正确访问它,但不确定。

  //This line will output the carouselurl
  <?php echo $hs_feefo_results->{'reviews'}[0]->{'service'}->{'media'}[0]-> 
       {'carouselUrl'};?>

   //I need for it to work in here to be able to use it in posts.
    $feefo_data = wp_remote_get( 'https://api.feefo.com/api/10/reviews/all?merchant_identifier=hide-and-seek-travel' );

    $feefo_data_decode = json_decode( $feefo_data['body'] );


    foreach ( $feefo_data_decode->reviews as $item ) {
        $feefo_id                                   =$item->service->id;
        $post_title                             = $item->service->title; // post title
        $post_content                           = $item->service->review;
        $feefo_display_names            =   $item->customer->display_name;
        $feefo_display_location     =   $item->customer->display_location;
        $feefo_rating                           =   $item->service->rating->rating;
        $feefo_image_url                    =   $item->service->media->carouselUrl;

    $my_post = array(
        'post_title'        => $post_title,
        'post_content'  => $post_content,
        'post_status'       => 'publish',
        'post_type'         => 'feefo_reviews',
        'meta_input'        => array(
            'feefo_id'          => $feefo_id
        )
    );

    $mg_args = array(
        'post_type'         => 'feefo_reviews',
        'meta_query'        => array(
            array(
                'key'               => 'feefo_id',
                'value'             => $feefo_id,
            )
        )
    );

    $mg_query =new WP_Query( $mg_args );
        if( $mg_query ->have_posts()){

        }else{
            $post_id = wp_insert_post( $my_post );

            update_field( 'feefo_display_names', $feefo_display_names, $post_id );
            update_field( 'feefo_display_location', $feefo_display_location, $post_id );
            update_field( 'feefo_rating', $feefo_rating, $post_id );
            update_field( 'feefo_id', $feefo_id , $post_id );
            update_field( 'feefo_images', $feefo_image_url, $post_id );
            wp_reset_postdata();
            }

我希望在发布字段中看到该URL,但是什么也看不到。

我得到的错误是-> 注意:尝试获取非对象中的属性'carouselUrl'

0 个答案:

没有答案