added shortcode to print error addresses

This commit is contained in:
lenovo
2022-11-09 13:17:21 +01:00
parent 163eaa2f04
commit 80c1683904
2 changed files with 46 additions and 0 deletions

View File

@@ -100,6 +100,7 @@ function mp_add_div() {
wp_enqueue_style('mp_style_zoom', plugins_url('styles/mp_zoom.css', __FILE__), '', '', false);
wp_enqueue_script('mp_info_window', plugins_url('scripts/mp_info_window.js', __FILE__), '', '', false);
wp_enqueue_script('mp_errors', plugins_url('scripts/mp_errors.js', __FILE__), '', '', false);
wp_enqueue_script('mp_create_markers', plugins_url('scripts/mp_create_markers.js', __FILE__), '', '', false);
wp_enqueue_script('mp_draw_clusters', plugins_url('scripts/mp_draw_clusters.js', __FILE__), '', '', false);
wp_enqueue_script('mp_marker_clusterer', $marker_clusterer, '', '', true);
@@ -137,6 +138,44 @@ add_shortcode('lejourduprof_map', 'mp_add_div');
/**
* errors map
*/
function mp_errors_map() {
$errors = "";
$count = 0;
$get_posts_args = array(
'numberposts' => -1,
'post_status' => 'publish',
//'post_status' => 'draft',
'post_type' => 'post',
);
$posts = get_posts($get_posts_args);
foreach ($posts as $post) {
$id = $post->ID;
$coordinate = get_field('coordinates', $id);
if ($coordinate == null) {
$count++;
$errors .= '<br /><p>erreur :</p><p>- article : "';
$errors .= $post->post_title . '"</p><p>- adresse : "';
$errors .= get_field('adresse', $id) . ', ';
$errors .= get_field('ville', $id) . ', ';
$errors .= get_field('pays', $id) . '';
$errors .= '"</p>';
}
}
$errors = "<p>nombre d'erreurs : " . $count . "</p>" . $errors;
return $errors;
}
add_shortcode('ljdp_errors_map', 'mp_errors_map');
/**
* when a post is saved or published or updated,
* find its coordinates

View File

@@ -0,0 +1,7 @@
function print_error(error) {
let div_map = document.getElementById("ljdp_map");
let p_err = document.createElement('p');
p_err.textContent = error;
div_map.after(p_err);
}