-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() { // TESTS // script to publish or unpublish 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_status' => 'draft', 'post_type' => 'post', ); $posts_published = get_posts($get_posts_args); // // "get_post" // // https://developer.wordpress.org/reference/functions/get_posts/ // $post = $posts_published[0]; // mp_console_log("get post:"); // mp_console_log($post); // // https://developer.wordpress.org/reference/functions/get_post_meta/ // $post_meta = get_post_meta($post->ID); // mp_console_log("get post meta:"); // mp_console_log($post_meta); // // same as "get_post_meta", but cannot specify a key // // and is optimized for cache // // https://developer.wordpress.org/reference/functions/get_post_custom/ // $post_custom = get_post_custom($post->ID); // mp_console_log("get post custom:"); // mp_console_log($post_custom); // // get fiels 'coordinates' // $field_coordinates = get_field('coordinates', $post->ID); // mp_console_log("get field coordinates:"); // mp_console_log($field_coordinates); // // get fiels 'ID' // $field_id = get_field('ID', $post->ID); // mp_console_log("get field ID:"); // mp_console_log($field_id); // // get fiels 'post_title' // $field_title = get_field('post_title', $post->ID); // mp_console_log("get field title:"); // mp_console_log($field_title); return $posts_published; } /* GET POST : ID: 29693 comment_count: "0" comment_status: "closed" filter: "raw" guid: "https://local_lejourduprof.com/?p=29693" menu_order: 0 ping_status: "closed" pinged: "" post_author: "1" post_content: "" post_content_filtered: "" post_date: "2022-11-04 18:05:49" post_date_gmt: "2022-11-04 17:05:49" post_excerpt: "Les enseignants vont présenter les projets développés dans leurs classes et partager leurs pratiques et expériences." post_mime_type: "" post_modified: "2022-11-05 09:39:46" post_modified_gmt: "2022-11-05 08:39:46" post_name: "construisons-ensemble-lavenir" post_parent: 0 post_password: "" post_status: "draft" post_title: "Construisons ensemble l'avenir" post_type: "post" to_ping: "" */ function mp_fill_fields_value($id) { // get_field is an ACF function // in "pure" worpdress use : // get_post_meta or get_post_custom_values $fields = array( "heure_de_debut", "heure_de_fin", "categorie", "date", "pays", "ville", "adresse", "prenom", "nom", "coordinates", ); $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; } ?>