Home › Forums › Backend Issues (wp-admin) › Custom Location Rule for Custom Taxonomy › Reply To: Custom Location Rule for Custom Taxonomy
Hey James,
That helped fixed many of the problems.
The only issue I am having is with it updating on the AJAX calls.
When I select a new category and then save and reload the page, the correct fields show up, but only on page reload.
I used Chrome’s inspector to monitor the network calls. Every time a new category is selected (it is a drop-down) then there are two POST calls to admin-ajax.php. Both calls return a 200 status, but the page does not update to show the correct fields, until I save and reload.
Are there other steps needed to make the AJAX calls update the edit page?
This is the current state of the code now:
function acf_location_rules_types_product_category($choices) {
// create a new group for the rules called Terms
// if it does not already exist
if (!isset($choices['Products'])) {
$choices['Products'] = array();
}
// create new rule type in the new group
$choices['Products']['fr_product_categories'] = 'Category Name';
return $choices;
}
function acf_location_rules_values_product_category($choices) {
// get terms and build choices
$all_categories = get_terms('fr_product_categories', array('hide_empty' => false, 'childless' => true, 'orderby' => 'name'));
if(count($all_categories)){
foreach($all_categories as $category){
$choices[$category->term_id] = $category->name;
}
}
return $choices;
}
function acf_location_rules_match_product_category($match, $rule, $options){
// validate
if(!$options['post_id']){return false;}
$category = intval(get_post_meta($options['post_id'], 'product_category', true));
if($rule['operator'] == "=="){
$match = $rule['value'] == $category;
}
elseif($rule['operator'] == "!="){
$match = $rule['value'] != $category;
}
return $match;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.