Из одного проекта код:
// Карта Яндекс
add_theme_support( 'post-thumbnails' );
function yandex_map_all(){
global $wpdb;
$products = $wpdb->get_results("SELECT ID FROM `ev_posts` WHERE `post_type`='product' AND `post_status`='publish'");
$result = array();
foreach($products as $product){
$result[] = $product->ID;
}
the_multiple_yandex_map($result);
}
function the_multiple_yandex_map($post_ids = array()){
$marks = array(); // Все метки
$marks_counter = 1;
foreach ($post_ids as $post_id) {
$data = (array)json_decode(get_field('halls_mapya', $post_id, false), true); // загрузка меток из записи
if (!isset($data['marks']) || !is_array($data['marks'])) {
continue;
}
foreach ((array)$data['marks'] as $mark) {
$mark['id'] = $marks_counter;
$mark['content'].='<a href="'.get_permalink($post_id).'">'.get_the_title($post_id).'</a>';
$mark['content'].=get_the_post_thumbnail($post_id);
$marks[] = $mark;
$marks_counter++;
}
}
$map_data = (array)json_decode(get_field('halls_mapya', get_the_ID(), false), true); // загрузка параметров карты для вывода всех меток
if(is_product_category('61','75')) {
$map_data = array(
"center_lat" => 59.936803,
"center_lng" => 30.309590,
"zoom" => 12,
"type" => "map"
);
}else{
$map_data = array(
"center_lat" => 55.755456,
"center_lng" => 37.623104,
"zoom" => 10,
"type" => "map"
);
}
$map_data['marks'] = $marks;
the_yandex_map('', false, json_encode($map_data), 450);
}