paolo_bortolotti

mappa

Jul 29th, 2021
28
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. _____
  2. js
  3.  
  4.  
  5.  
  6. jQuery(document).ready(function($){
  7. jQuery('.mappa').each(function() {
  8. jQuery(this).magnificPopup({
  9. delegate: 'a',
  10. type: 'inline',
  11. midClick: true
  12. });
  13. });
  14.  
  15. jQuery('.mappa a').click(function(){
  16. // alert("The id is "+ jQuery(this).attr("data-id") );
  17. var postid = jQuery(this).attr("data-postid");
  18. console.log(postid);
  19.  
  20. $.ajax({
  21. type: "POST",
  22. url: my_ajax_object.ajax_url,
  23. data: {
  24. action: 'my_load_ajax_content',
  25. postid: postid,
  26. }
  27. }).done(function (data) {
  28. // Just simple html() method with data will show all the content.
  29. jQuery('#opencomune').html(data);
  30. });
  31. });
  32. });
  33. ____
  34.  
  35.  
  36. Page Mappa
  37.  
  38. <div id="opencomune" class="mfp-hide">
  39. <?php my_load_ajax_content(); ?>
  40. </div>
  41.  
  42. ----
  43.  
  44.  
  45. function my_load_ajax_content() {
  46. if ( isset($_REQUEST["postid"]) ) {
  47. $pid = $_REQUEST["postid"];
  48. }
  49.  
  50. $args = array(
  51. 'post_type' => 'eventi',
  52. 'order' => 'ASC',
  53. 'posts_per_page' => -1
  54. );
  55. $the_query = new WP_Query($args);
  56.  
  57. if ($the_query->have_posts()) {
  58. while ( $the_query->have_posts() ) {
  59. $the_query->the_post();
  60.  
  61. $featured_posts = get_field('comune_della_provincia'); if( $featured_posts ):
  62. foreach( $featured_posts as $post ):
  63. setup_postdata($post);
  64. $permalink = get_permalink( $post->ID );
  65. $title = get_post_field( 'post_name' , $post->ID );
  66. $string = '<span></span>'; ?>
  67.  
  68. <?php if ($title == $pid) {
  69. echo get_the_title();
  70. ?>
  71.  
  72. <?php } else {
  73. } ?>
  74.  
  75.  
  76.  
  77. <?php
  78. endforeach;
  79. wp_reset_postdata();
  80. endif;
  81.  
  82. }
  83. } else {
  84.  
  85. $data = '<div id="postdata">'.__('Didnt find anything', THEME_NAME).'</div>';
  86. }
  87. wp_reset_postdata();
  88.  
  89. echo '<div id="postdata">' . $data .'</div>';
  90. // And must die() the function
  91. die();
  92. }
  93.  
  94. add_action( 'wp_ajax_nopriv_my_load_ajax_content', 'my_load_ajax_content' );
  95. add_action( 'wp_ajax_my_load_ajax_content', 'my_load_ajax_content' );
  96.  
  97.  
RAW Paste Data