0
我在WordPress網站上使用Advanced Custom Fields plugin。我打算有一個自定義位置規則來顯示自定義分類中的任何詞語被選中時自定義歸檔組。高級自定義字段 - 匹配自定義分類的自定義位置規則
繼ACF網站上的custom location rule tutorial後,我在規則行中添加了自定義類型,運算符和值。
我的匹配函數(下面的代碼)只在頁面重新載入時才起作用,但不能通過AJAX起作用。如何將自定義分類添加到$ options數組中,以便匹配函數可以在定製分類術語被選中/取消選中時通過AJAX進行評估。
function acf_location_rules_match_taxonomyTerm($match, $rule, $options){
// vars
$taxonomies = get_object_taxonomies($options['post_type']);
$terms = $options['taxonomy'];
// not AJAX
if(!$options['ajax']){
// no terms? Load them from the post_id
if(empty($terms)){
if(is_array($taxonomies)){
foreach($taxonomies as $tax){
$all_terms = get_the_terms($options['post_id'], $tax);
if($all_terms){
foreach($all_terms as $all_term){
$terms[] = $all_term->term_id;
}
}
}
}
}
if($rule['operator'] == "<==>"){
$match = false;
if($terms){
$current_terms = get_the_terms($options['post_id'], $rule['value']);
if ($current_terms && ! is_wp_error($terms)) {
$current_term_ids = array();
foreach ($current_terms as $current_term) {
$current_term_ids[] = $current_term->term_id;
}
}
foreach ($current_term_ids as $current_term_id) {
if(in_array($current_term_id, $terms)){
$match = true;
}
}
}
}
else{
$match = false;
}
}
return $match;
}
謝謝回答以前沒有答案的問題,但它是最好的,包括文本或代碼的小片段從你的鏈接,如果你能 –