I have a situation where only way seems to use loop inside a loop. Is that a good idea?
Like everybody else, Im looking for the most optimized solution possible.
Situation:
- I need to assing different markers for each type (these are taxonomies).
- Yes, these markers are markers on Google Map API.
- My code below is inside while loop that gets all posts I need.
- URL from code is then used in Google Map JS to assing marker image.
What I've got:
// Types
$car_type = get_the_terms( $post->ID, 'car-type' );
foreach ( $car_type as $type ) {
$type_slug = $type->slug;
foreach ( $type_slug as $type_slug ) {
$marker_image = 'https://www.my-site.com/media/markers/marker_' . $type_slug . '.png';
}
}