Status

Terminé

En cours

Prévu


Associé-e BBE
Label

Label haie

Label végétal local

Type de projet

Lieux de plantation

Producteur de bois

Acheteur de bois

Acheteur de chaleur

Plateforme logistique

post_content, 'cartographie')) { 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 wp_posts.ID, wp_posts.post_title, wp_term_taxonomy.taxonomy, GROUP_CONCAT(wp_terms.term_id ORDER BY wp_terms.term_id) AS term_ids, GROUP_CONCAT(wp_terms.name ORDER BY wp_terms.term_id) AS term_names FROM wp_posts INNER JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id INNER JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id INNER JOIN wp_terms ON wp_term_taxonomy.term_id = wp_terms.term_id WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'markercartographie' GROUP BY wp_posts.ID, wp_term_taxonomy.taxonomy; "); $structured_data = []; $image_results = $wpdb->get_results(" SELECT wp_posts.ID, wp_postmeta.meta_value AS image_id, image_posts.guid AS image_url FROM wp_posts LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_thumbnail_id' LEFT JOIN wp_posts AS image_posts ON wp_postmeta.meta_value = image_posts.ID WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'markercartographie'; "); $image_data = []; foreach ($image_results as $image_row) { $image_data[$image_row->ID] = [ 'image_id' => $image_row->image_id, 'image_url' => $image_row->image_url, ]; } foreach ($results as $row) { if (!isset($structured_data[$row->ID])) { $structured_data[$row->ID] = [ 'name' => $row->post_title, ]; } // Ajouter les termes (taxonomies) if ($row->taxonomy == "categorielabel") { $structured_data[$row->ID][$row->taxonomy] = explode(",", $row->term_names); } else { $structured_data[$row->ID][$row->taxonomy] = $row->term_names; } // Ajouter l'image mise en avant si elle existe if (isset($image_data[$row->ID])) { $structured_data[$row->ID]['image'] = $image_data[$row->ID]; } } return $structured_data; }