Type de projet
Lieux de plantation
Producteur de bois
Acheteur de bois
Acheteur de chaleur
post_content, 'hello_world_map')) {
wp_enqueue_style(
'leaflet-css',
'https://unpkg.com/leaflet@1.9.3/dist/leaflet.css',
array(),
'1.9.3'
);
wp_enqueue_script(
'leaflet-js',
'https://unpkg.com/leaflet@1.9.3/dist/leaflet.js',
array(),
'1.9.3',
true
);
wp_enqueue_style(
'leaflet-markercluster-css',
'https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.Default.css'
);
wp_enqueue_script(
'leaflet-markercluster-js',
'https://unpkg.com/leaflet.markercluster@1.5.3/dist/leaflet.markercluster.js',
array('leaflet-js', 'jquery'),
null,
true
);
wp_enqueue_script(
'hello-world-script',
plugin_dir_url(__FILE__) . 'js/main.js',
array('leaflet-js', 'leaflet-markercluster-js'),
'1.0',
true
);
wp_enqueue_style(
'hello-world-style',
plugin_dir_url(__FILE__) . 'css/style.css',
array(),
'1.0'
);
}
}
add_action('rest_api_init', function() {
register_rest_route('custom/v1', '/markers', array(
'methods' => 'GET',
'callback' => 'get_cartographie_markers',
));
});
function get_cartographie_markers() {
global $wpdb;
$table_name = $wpdb->prefix . 'posts';
$results = $wpdb->get_results("
SELECT u3yd_posts.ID, u3yd_posts.post_name, u3yd_term_taxonomy.taxonomy,
GROUP_CONCAT(u3yd_terms.term_id ORDER BY u3yd_terms.term_id) AS term_ids,
GROUP_CONCAT(u3yd_terms.name ORDER BY u3yd_terms.term_id) AS term_names
FROM u3yd_posts
INNER JOIN u3yd_term_relationships ON u3yd_posts.ID = u3yd_term_relationships.object_id
INNER JOIN u3yd_term_taxonomy ON u3yd_term_relationships.term_taxonomy_id = u3yd_term_taxonomy.term_taxonomy_id
INNER JOIN u3yd_terms ON u3yd_term_taxonomy.term_id = u3yd_terms.term_id
WHERE u3yd_posts.post_status = 'publish'
AND u3yd_posts.post_type = 'markercartographie'
GROUP BY u3yd_posts.ID, u3yd_term_taxonomy.taxonomy;
");
$structured_data = [];
foreach ($results as $row) {
if(!isset($structured_data[$row->ID])){
$structured_data[$row->ID] = [
'name' => $row->post_name,
];
}
if ($row->taxonomy == "categorielabel") {
$structured_data[$row->ID][$row->taxonomy] = explode(",", $row->term_names);
} else {
$structured_data[$row->ID][$row->taxonomy] = $row->term_names;
}
}
return $structured_data;
}