Почему не работает ajax в wordpress: открытие поста в модальном окне?

У меня такая проблема. Я пытаюсь сделать так, чтобы все посты, которые выводятся на главной странице через цикл открывались не в новом окне, а в модальном окне из bootstrap. Проблема в том, что почему-то работает не совсем так, как хотелось бы - не работает. Модальное-то окно оно открывает, но пустое, без статьи. Вот как все работает: в functions.php я поместил вот такой код:

add_action('wp_ajax_my_action', 'data_fetch');
add_action('wp_ajax_nopriv_my_action', 'data_fetch');
function data_fetch($postID){
    $postID=intval( $_POST['param'] );

    $args = array(
    ‘p’ => $postID, // ID of a page, post, or custom type
    //’post_type’ => ‘any’
    );
    $recent = new WP_Query($args);
    while ( $recent->have_posts() ) : $recent->the_post();?>
        <div class=»modal-header»>
        <button type=»button» class=»close» data-dismiss=»modal» aria-label=»Close»><span aria-hidden=»true»>&times;</span></button>
        <?php the_title( '<h2 class=»modal-title text-center»>', '</h5>' ); ?>
        </div>
        <div class=»modal-content»>
        <div class=»conterer″>
            <img src=»<?php echo get_the_post_thumbnail_url(); ?>» class=»instaupp-img img-circle»>
        </div>
            <div class=»conterer″>
                <p><i>Описание</i></p>
            </div>
        </div>
    <?php endwhile; ?>
<?php
    die();
}

Затем, в index.php я сделал вот это:

<?php query_posts('cat=2');
        $args = array(
          'p' => $postID, // ID поста
          'post_type' => 'any'
          );
          $recent = new WP_Query($args);
                                    ?>
        <?php if (have_posts()) :  while (have_posts()) : the_post(); ?>
        <div class="oneNew p1" style="background-image: url(img/newBg.png)">
            <a href="#" data-toggle="modal" data-target=".bd-example-modal-xl" data-ajax-param="<?php the_ID(); ?>"><?php the_title( '<h2 class="modal-title text-center">', '</h2>' ); ?></a>                      
          </div>    
        <?php endwhile; ?>
        <?php endif; ?>

А так же в этом же index.php скрипт:

<script>
function fetch(e){var param = $(e.target).attr('data-ajax-param');
 // поиск id поста
  $.post('wp-admin/admin-ajax.php', {'action':'my_action', 'param':param}, function(response){
   $('.modal-content.ajax').html(response);
});
}
</script>
<script>
$( '[data-ajax-param]' ).click(function (e) {
 fetch(e);
});
</script>

Ну, и в footer.php html-верстка этого самого модального окна:

<div class="modal fade bd-example-modal-xl modal-content.ajax" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
    	<div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel"></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      ... <div class="conterer">

      </div>
    </div>
  </div>
</div>

По нажатию на новость открывается модальное окно, но пустое, без всего. Где может быть ошибка или не так где-то что-то работает? Спасибо


Ответы (0 шт):