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'));
            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;