php filter wrong addresses

This commit is contained in:
lenovo
2022-11-05 14:26:06 +01:00
parent 79ed319b8f
commit 56850e9b2f
2 changed files with 11 additions and 3 deletions

View File

@@ -11,7 +11,10 @@ function mp_get_coordinates($id) {
);
$event = (object)[];
foreach($fields as $field) {
$event->$field = get_field($field, $id);
$address_part = get_field($field, $id);
if ($address_part == '')
return null;
$event->$field = $address_part;
}
// concat as an address

View File

@@ -159,10 +159,15 @@ 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;
array_push($events, $event);
$event = mp_fill_fields_value($post->ID);
// only add to array if address is complete
if ( isset($event->coordinates) )
array_push($events, $event);
else
mp_console_log("event address incomplete:");
mp_console_log($event);
}
mp_console_log($events);
return $events;