Wordpress 使用两个选择字段筛选acf关系字段(acf)

Wordpress 使用两个选择字段筛选acf关系字段(acf),wordpress,relationship,advanced-custom-fields,Wordpress,Relationship,Advanced Custom Fields,我的问题与此类似,但我想更进一步 我的管理区域和关系字段中有两个acf选择字段。这两个select字段都加载了自定义分类法。第一个叫做Pool,第二个叫做Month。池可以是这些值A、B或C中的一个。月份字段只是一年中的月份。“关系”字段显示自定义帖子类型中的所有帖子 当我选择一个池时,我看到关系中的结果被过滤,这很好。当我选择一个月时,我可以看到它们被进一步过滤。都是好消息。我点击帖子上的更新按钮,我的值被保存 我有两个问题 首先,当我回到页面时,我的过滤器还没有被激活。我使用wp_ajax调

我的问题与此类似,但我想更进一步

我的管理区域和关系字段中有两个acf选择字段。这两个select字段都加载了自定义分类法。第一个叫做Pool,第二个叫做Month。池可以是这些值A、B或C中的一个。月份字段只是一年中的月份。“关系”字段显示自定义帖子类型中的所有帖子

当我选择一个池时,我看到关系中的结果被过滤,这很好。当我选择一个月时,我可以看到它们被进一步过滤。都是好消息。我点击帖子上的更新按钮,我的值被保存

我有两个问题

首先,当我回到页面时,我的过滤器还没有被激活。我使用wp_ajax调用来更新relationship字段

其次,当我回来编辑同一篇文章时,我可以看到关系字段左侧的所有文章以及我在右侧选择的文章。当我和my pool和month过滤器交互时,“关系”字段左侧的所有结果都会像应该的一样发生更改,但问题是我选择并显示在右侧的结果现在也会再次显示在左侧,并且不会被禁用

最后,我想做的是当我编辑页面时,我希望我的过滤器已经处于活动状态。这意味着关系字段应该使用我在保存之前已经选择的选项进行过滤

如果已经选择的值出现在右侧,我还希望在左侧禁用这些值

我需要做些什么才能让它工作

admin_site.js jQuery document.readyfunction{

jQuery('.tips-pool select, .tips-month select').change(function(){

    var tipsPoolSelected = jQuery('.tips-pool select').val();
    var tipsMonthSelected = jQuery('.tips-month select').val();

    console.log("tipsPoolSelected: " + tipsPoolSelected);
    console.log("tipsMonthSelected: " + tipsMonthSelected);    

    jQuery.ajax({
        url: "/wp-admin/admin-ajax.php",
        type: 'POST',
        data: {
            action: 'filter_by_tips',
            tips_pool_selected: tipsPoolSelected,
            tips_month_selected: tipsMonthSelected,
        },
        dataType: 'html',
        success: function (result) {
            //Use the html to populate your time select field
            jQuery('.tips-relationship .selection .choices ul.acf-bl.list').html( result );
            console.log("result: " + result);
        },
        error: function (errorThrown) {
            console.log(errorThrown);
        }
    });

});

});
functions.php

// Function to hook into from the select
add_action('wp_ajax_filter_by_tips', 'filter_by_tips');
add_action('wp_ajax_nopriv_filter_by_tips', 'filter_by_tips');

/**
 * Get the tips filter by pool cat id
 */
function filter_by_tips(){
  global $wpdb;

  $html_select = NULL;

  // pool_cat_slug
  if($_POST['tips_pool_selected']){
    $pool_cat_slug = $_POST['tips_pool_selected'];
  }

  // month_cat_value
  if($_POST['tips_month_selected']){                        
     $month_cat_slug = strtolower($_POST['tips_month_selected']);
  }

                $args = array(
                    'post_type' => 'daily-marriage-tips',
                    'tax_query' => array(
                        'relation' => 'AND',
                        array(
                            'taxonomy' => 'cat_tips',
                            'field'    => 'slug',
                            'terms'    => $pool_cat_slug,
                        ),
                        array(
                            'taxonomy' => 'cat_months',
                            'field'    => 'slug',
                            'terms'    => $month_cat_slug,
                        ),
                    ),
                );
    $query = new WP_Query( $args );
    if( $query->have_posts() ):
      while ($query->have_posts()) : $query->the_post();
        $post_id = get_the_ID();
        $post_title = get_the_title();

        $html_select = '<li><span class="acf-rel-item" data-id="'.$post_id.'">'.$post_title.'</li>';

        endwhile;
    endif;

    if($html_select){
      echo $html_select;
    }   

    unset($pool_cat_slug);
    unset($tips_month_selected_array);

    exit;
}