-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) { /* * 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", "location", ); $event = (object)[]; foreach($fields as $field) { $value = get_field($field, $id); if (gettype($value) == "string") $value = trim($value, " "); $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; // add post url $event->url = get_post_permalink($id); return $event; } 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 = trim($post->post_title, " "); $event->index = null; array_push($events, $event); } return $events; } /* event : {} - heure_de_debut : ""; - heure_de_fin : ""; - categorie : ""; - date : ""; - pays : ""; - ville : ""; - adresse : ""; - prenom : ""; - nom : ""; - irl : bool; - id : x; - index : x (default null); - title : ""; - url : ""; - location : {} - street : ""; - city : ""; - country : ""; - address : ""; - approximate : bool; - coordinates : {} - lat : x; - lng : x; */ ?>