Last active
October 30, 2016 14:12
-
-
Save martijngastkemper/350bda966be1d4e411db01a561ef89e5 to your computer and use it in GitHub Desktop.
Create a custom ACF rule to match all pages having a taxonomy enabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// functions.php | |
add_filter('acf/location/rule_types', 'acf_location_rules_types'); | |
function acf_location_rules_types( $choices ) { | |
$choices['Post']['post-type-has-taxonomy'] = __('Post Type has Taxonomy'); | |
return $choices; | |
} | |
add_filter( 'acf/location/rule_values/post-type-has-taxonomy', 'acf_location_rules_values_has_taxonomy' ); | |
function acf_location_rules_values_has_taxonomy( $choices ) { | |
return array_merge($choices, get_taxonomies()); | |
} | |
add_filter('acf/location/rule_match/post-type-has-taxonomy', 'acf_location_rules_match_has_taxonomy', 10, 3); | |
function acf_location_rules_match_has_taxonomy( $match, $rule, $options ) | |
{ | |
if ($rule['operator'] == '==') { | |
$match = is_object_in_taxonomy($options['post_type'], $rule['value']); | |
} elseif ($rule['operator'] == '!=') { | |
$match = !is_object_in_taxonomy($options['post_type'], $rule['value']); | |
} | |
return $match; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment