if (is_page('ubicacion')) {
$args = array(
'post_type' => 'paises',
'posts_per_page' => -1,
);
$query = new WP_Query($args);
$data = array();
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$slug = strtolower(get_post_meta(get_the_ID(), '_pais_slug', true));
$contacto = get_post_meta(get_the_ID(), '_contacto', true);
$direccion = get_post_meta(get_the_ID(), '_direccion', true);
$correos = get_post_meta(get_the_ID(), '_correos', true);
$telefonos = get_post_meta(get_the_ID(), '_telefonos', true);
$whatsapps = get_post_meta(get_the_ID(), '_whatsapps', true);
$flag_url = "https://flagcdn.com/w80/{$slug}.png";
$data[$slug] = array(
'name' => get_the_title(),
'flag' => $flag_url,
'type' => 'Oficina Regional',
'status' => 'regional',
'contacts' => array(
'address' => array(
'label' => 'Dirección',
'value' => wpautop($direccion),
'icon' => 'map-marker-alt',
),
'phones' => array(
'label' => 'Teléfonos',
'icon' => 'phone',
'multiple' => true,
'values' => array_map(function ($tel) {
return array(
'label' => 'Número',
'number' => $tel,
'link' => 'tel:' . preg_replace('/\D/', '', $tel),
);
}, $telefonos ?: []),
),
'whatsapp' => array(
'label' => 'WhatsApp',
'icon' => 'comment',
'multiple' => true,
'values' => array_map(function ($wa) {
return array(
'label' => 'Número',
'number' => $wa,
'link' => 'https://wa.me/' . preg_replace('/\D/', '', $wa),
);
}, $whatsapps ?: []),
),
'email' => array(
'label' => 'Correo Electrónico',
'icon' => 'envelope',
'value' => implode(', ', array_map(function ($mail) {
return '<a href="mailto:' . $mail . '">' . $mail . '</a>';
}, $correos ?: [])),
),
),
);
}
wp_reset_postdata();
}
wp_localize_script('maps-js', 'contactData', $data);
}