Skip to content

Instantly share code, notes, and snippets.

@khromov
Created October 2, 2017 17:36
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save khromov/872e7642f181d959845012091d22d4a6 to your computer and use it in GitHub Desktop.
"Nowhere" location rule for Advanced Custom Fields - never matches
<?php
/*
Plugin Name: Advanced Custom Fields: Nowhere location rules
Description: Adds a "Nowhere" location rule in ACF
*/
add_filter('acf/location/rule_types', function($rules) {
$rules['Extra']['nowhere'] = 'Nowhere';
return $rules;
});
add_filter('acf/location/rule_operators/nowhere', function($choices) {
if(isset($choices['=='])) {
unset($choices['==']);
}
if(isset($choices['!='])) {
unset($choices['!=']);
}
$choices['nowhere'] = '-';
return $choices;
});
add_filter('acf/location/rule_values/nowhere', function($choices) {
return ['nowhere' => '-'];
});
add_filter('acf/location/rule_match/nowhere', function($match, $rule, $options) {
return false;
}, 10, 3);
@khromov
Copy link
Author

khromov commented Oct 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment