-1, // 'post_status' => 'publish', // 'post_type' => 'acf-field', // ); // $forms = get_posts($get_form_args); // $fields = []; // foreach ($forms as $form) { // $field = $form->post_excerpt; // array_push($fields, $field); // } // return $fields; //} function mp_get_published_posts() { // $post_args = array( // 'numberposts' => -1, // 'post_status' => 'draft', // //'post_status' => 'publish', // 'post_type' => 'post', // ); // $post_list = get_posts($post_args); // foreach ($post_list as $post) { // wp_update_post(array( // 'ID' => $post->ID, // //'post_status' => 'draft', // 'post_status' => 'publish', // )); // } $get_posts_args = array( 'numberposts' => -1, 'post_status' => 'publish', 'post_type' => 'post', ); $posts_published = get_posts($get_posts_args); return $posts_published; } function mp_fill_fields_value($id) { $fields = array( "heure_de_debut", "heure_de_fin", "categorie", "date", "pays", "ville", "adresse", "prenom", "nom", ); $event = (object)[]; foreach($fields as $field) { $event->$field = get_field($field, $id); } $presentiel = get_field("mode", $id); $event->irl = false; if ($presentiel[0] === "En présentiel") $event->irl = true; return $event; } function mp_get_coordinates(&$marker) { global $mp_api_key; $address = $marker->adresse . "," . $marker->ville . "," . $marker->pays; $geolocation = 'https://maps.googleapis.com/maps/api/geocode/json' . '?address=' . urlencode($address) . '&key=' . $mp_api_key; $jsoncontent = file_get_contents($geolocation); $content = json_decode($jsoncontent); $coordinates = $content->results[0]->geometry->location; return $coordinates; } function mp_get_published_events() { $posts_list = mp_get_published_posts(); $events = []; foreach ($posts_list as $post) { $event = mp_fill_fields_value($post->ID); $event->id = $post->ID; $event->title = $post->post_title; // $event->coordinates = mp_get_coordinates($event); array_push($events, $event); } mp_console_log($events); return $events; } ?>