See https://neliosoftware.com/blog/the-problems-of-using-nested-loops-in-wordpress/
|
public static function flGetLocations($postType): array |
|
{ |
|
$locations = []; |
|
$locQuery = new WP_Query([ |
|
'post_type' => $postType, |
|
'meta_key' => 'location', |
|
'meta_query' => [ |
|
[ |
|
'key' => 'location', |
|
'value' => '', |
|
'compare' => '!=', |
|
], |
|
], |
|
]); |
|
|
|
if ($locQuery->have_posts()) { |
|
while ($locQuery->have_posts()) { |
|
$locQuery->the_post(); |
|
$location = get_field('location', get_the_ID()); |
|
if (! array_key_exists($location, $locations)) { |
|
$locations[esc_attr($location)] = $location; |
|
} |
|
} |
|
} |
|
|
|
wp_reset_postdata(); |
|
|
|
return $locations; |
|
} |
See https://neliosoftware.com/blog/the-problems-of-using-nested-loops-in-wordpress/
sage-flbuilder/src/God.php
Lines 39 to 67 in e574bdf