-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() { // FOR 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); return $posts_published; } function mp_fill_fields_value($id, &$pays) { /* * get_field is an ACF function * in "pure" worpdress use : * get_post_meta or get_post_custom_values * - https://developer.wordpress.org/reference/functions/get_post_meta/ * - https://developer.wordpress.org/reference/functions/get_post_custom_values/ */ // add fields $fields = array( "heure_de_debut", "heure_de_fin", "categorie", "date", "pays", "ville", "adresse", "prenom", "nom", "coordinates", "coordinates_valid", ); $event = (object)[]; foreach($fields as $field) { $value = get_field($field, $id); $event->$field = $value; } // add mode irl or online (irl: true | false) $presentiel = get_field("mode", $id); $event->irl = false; if ($presentiel[0] === "En présentiel") $event->irl = true; return $event; } function mp_get_published_events(&$pays) { $posts_list = mp_get_published_posts(); $events = []; foreach ($posts_list as $post) { $event = mp_fill_fields_value($post->ID, $pays); $event->id = $post->ID; $event->title = $post->post_title; array_push($events, $event); } mp_console_log("nombre de posts: " . count($events)); return $events; } ?>