-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 * - https://developer.wordpress.org/reference/functions/get_post_meta/ * - https://developer.wordpress.org/reference/functions/get_post_custom/ * if you try to use `get_fields(id)` to retrieve all the acf7 custom fields, * sometimes it fails eventhough you can get a specific value with `get_field(value, id)`, * it's because acf7 didn´t insert the field itself and so some hidden data is not there : * - https://coreysalzano.com/wordpress/acf-get_fields-not-working-but-get_field-does/ */ // add fields $fields = array( "heure_de_debut" => "string", "heure_de_fin" => "string", "categorie" => "string", "date" => "string", "pays" => "string", "adresse" => "string", "prenom" => "string", "nom" => "string", "location" => "object", ); $event = (object)[]; foreach($fields as $field => $of_type) { $value = get_field($field, $id); //$actual_type = gettype($value); //if ($actual_type !== $of_type) { // mp_console_log("field '" . $field . "' has a value of type '" . $actual_type . "' instead of '" . $of_type . "'"); //} if ($value === "↓") $value = "Autre"; 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 (isset($presentiel[0])) { 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; -------------------------- Object { } */ ?>