Php 自定义分类的WordPress筛选器无法正常工作

Php 自定义分类的WordPress筛选器无法正常工作,php,ajax,wordpress,Php,Ajax,Wordpress,我正在努力解释我自己。我已经为我的自定义帖子类型更新创建了自定义分类法主题 现在我有了一个archive updates.php,在这里我创建了一个自定义的WPQuery来循环更新 我还设法循环使用我的自定义分类法,它返回一个列表 我想按分类法用Ajax过滤这个归档文件。但出于某种原因,它没有给出错误,而是一次又一次地循环和显示第一篇文章 My functions.php代码: function filter_themes() { $postType = $_POST['type'];

我正在努力解释我自己。我已经为我的自定义帖子类型
更新
创建了自定义分类法
主题

现在我有了一个
archive updates.php
,在这里我创建了一个自定义的WPQuery来循环更新

我还设法循环使用我的自定义分类法,它返回一个列表

我想按分类法用Ajax过滤这个归档文件。但出于某种原因,它没有给出错误,而是一次又一次地循环和显示第一篇文章

My functions.php代码:

function filter_themes() {
    $postType = $_POST['type'];
    $catSlug = $_POST['category'];

    $ajaxposts = new WP_Query([
      'post_type' => 'updates',
      'posts_per_page' => -1,
      'tag' => $catSlug,
      'orderby' => 'menu_order',
      'order' => 'desc',
    ]);
    $response = '';

    if($ajaxposts->have_posts()) {
      while($ajaxposts->have_posts()) : $ajaxposts->the_post();
        $response .= get_template_part('theme/template-parts/content', get_post_type());
      endwhile;
    } else {
      $response = 'empty';
    }

    echo $response;
    exit;
  }
  add_action('wp_ajax_filter_themes', 'filter_themes');
  add_action('wp_ajax_nopriv_filter_themes', 'filter_themes');
my archive-updates.php:

<?php
get_header();

$updates = new WP_Query([
    'post_type'         => 'updates',
    'posts_per_page'    => -1,
    'order_by'          => 'date',
    'order'             => 'DESC',
]);

$themes = get_terms(array(
    'taxonomy'   => 'themas',
    'hide_empty' => true,
));

$headings = get_terms(array(
    'taxonomy'   => 'rubrieken',
    'hide_empty' => true,
));
?>

<?php if($updates->have_posts()): ?>

    <h1><?php post_type_archive_title(); ?></h1>

    <br /><br /><br />

    <ul class="cat-list-themes">
        <li><a class="cat-list_item active" href="#!" data-slug="">Alle thema's</a></li>
        <?php foreach($themes as $theme): ?>
        <li>
            <a class="cat-list_item" href="#!" data-slug="<?= $theme->slug; ?>">
            <?= $theme->name; ?>
            </a>
        </li>
        <?php endforeach; ?>
    </ul>

    <?php
    while ($updates->have_posts()): $updates->the_post();
    get_template_part('theme/template-parts/content', get_post_type());
    endwhile;

    // Show the archive pagination.
    if (!function_exists('archive_pagination')):
    archive_pagination();
    endif;

    else:
    get_template_part('theme/template-parts/content', 'none');

    wp_reset_postdata();
    ?>

<?php endif; ?>

<script>
$('.cat-list_item').on('click', function() {
  $('.cat-list_item').removeClass('active');
  $(this).addClass('active');

  $.ajax({
    type: 'POST',
    url: '/wp-admin/admin-ajax.php',
    dataType: 'html',
    data: {
      action: 'filter_themes',
      taxonomy: $(this).data('slug'),
    },
    success: function(res) {
      console.log(res);
      $('.project-tiles').html(res);
    }
  })
});
</script>

<?php get_footer(); ?>




$('.cat-list_item')。在('click',function()上{ $('.cat-list_item').removeClass('active'); $(this.addClass('active'); $.ajax({ 键入:“POST”, url:“/wp admin/admin ajax.php”, 数据类型:“html”, 数据:{ 操作:“筛选主题”, 分类法:$(this).data('slug'), }, 成功:功能(res){ 控制台日志(res); $('.project tiles').html(res); } }) });