I'm getting some external data, and right away I'm inserting it into Wordpress, but this is going wrong by the fact that at the time of inserting, it still has not taken the data. How do I get first and then insert. I'll put the code here so you have an idea ...
<?php
//1:---------primeiro pegar os dados-----------------
$barco1= simplexml_load_file('https://api.consumer/rest-api/2.0/public/feed/xxxxxxxxxx/message.xml');
$i = 0;
foreach($barco1->feedMessageResponse->messages->message as $message) {
$i++;
}?>
<?php $latitude = $barco1->feedMessageResponse->messages->message[0]->latitude;?>
<?php $longitude = $barco1->feedMessageResponse->messages->message[0]->longitude;?>
<?php
//2:-----------depois que pegar os dados inserir no wordpres------------
$my_post = array(
'post_title' => 'Barco 1',
'post_status' => 'publish',
'post_type' => 'post',
'post_category' => array(1),
);
$post_id = wp_insert_post($my_post);
add_post_meta($post_id, 'Latitude', $barco1->feedMessageResponse->messages->message[0]->latitude);
add_post_meta($post_id, 'Longitude', $barco1->feedMessageResponse->messages->message[0]->longitude);
?>