$key) { $value = $_POST['meta_location_rule_value'][$i]; $choices[$key." : ".$value] = ""; } } // whichever rules we previously had for this field group, are also valid of // course foreach(get_post_meta(get_the_ID(), 'rule') ? : array() as $rule) { if ($rule['param'] !== 'meta_field') continue; $choices[$rule['value']] = ''; } return $choices; }); /** * When trying to find out whether this rule applies in the current scope. */ add_filter('acf/location/rule_match/meta_field', function($match, $rules, $post) { $compareOperaor = $rules['operator']; $compareKeyValue = $rules['value']; list($compareKey,$compareValue) = explode(" : ", $compareKeyValue, 2); // also add the fields to look for, to the header global $ACF_META_LOCATION_RULE_FIELDS; if (!isset($ACF_META_LOCATION_RULE_FIELDS)) $ACF_META_LOCATION_RULE_FIELDS = array(); $ACF_META_LOCATION_RULE_FIELDS[] = $compareKey; // fetch from db $postValue = get_post_meta($post['post_id'], $compareKey, true); // if from ajax, use the actual value from the form, instead of the // maybe-outdated db version if (isset($_POST['meta_location_rules']) && isset($_POST['meta_location_rules'][$compareKey])) { $postValue = $_POST['meta_location_rules'][$compareKey]; } switch($compareOperaor) { case '==': if ($postValue === $compareValue) $match = true; break; case '!=': if ($postValue !== $compareValue) $match = true; break; } return $match; }, 10, 3);