I’m receiving errors when I excute my wp insert function

Question

I need to interact my website with an API in the XML format to receive the feeds and store them in custom fields inside WordPress ..
I tried to write the code myself but I’m not the best with PHP so I received many errors especially with the wp insert post function
I will post my code here so you can guys tell me what I did wrong and what do you advise me. thank you.

function get_match_from_api(){
$current_match = 307049;
for($current_match;$current_match<=307051;$current_match++){
$result = simplexml_load_file(' the link' .$current_match);
$data = $result->v2_game_id;
if (empty($data)){
continue;
};
$match_slug = sanitize_title($current_match);
$inserted_match = wp_insert_post([
'post_name'=> $match_slug,
'post_type'=>'matchs',
'post_status'=> 'publish'
]);
$fillable = [
'field_5f45d3c547009' => '$result->stadium',
'field_5f45d15f54f95' => '$result->competition_name',
'field_5f45d36147006' => '$result->round'
];
foreach($fillable as $key => $name){
update_field($key, $name, $inserted_match)
};
};
};
0
, , , , saltah 3 months 0 Answers 49 views 0

Leave an answer