Last active
September 7, 2018 09:54
-
-
Save isuke01/51f742fa15cb3e3da9f74e9de7fd5195 to your computer and use it in GitHub Desktop.
ACF custom rules and match based on options (for custom page Archive in this case)
This file contains 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 | |
//More: https://www.advancedcustomfields.com/resources/custom-location-rules/ | |
// fis to work on keys instead of IDS | |
// Filter for ACF create field panel | |
add_filter('acf/location/rule_values/page_type', 'acf_location_rules_values_page', 10); // filter location | |
function acf_location_rules_values_page( $choices ) { | |
$choices['archive_for_projects'] = __('Projects archive page', 'ustekveikja'); // value and select box text | |
$choices['archive_for_neighborhood'] = __('Neighborhood archive page', 'ustekveikja'); // value and select box text | |
return $choices; | |
} | |
// Filter for ACF matching rule | |
add_filter('acf/location/rule_match/page_type', 'acf_location_rules_match_page', 10, 3); | |
function acf_location_rules_match_page( $match, $rule, $options ) | |
{ | |
$special = [ | |
'archive_for_projects' => get_archive_for_projects(), | |
'archive_for_neighborhood' => get_archive_for_neighborhood() | |
]; | |
$current_page = (isset($options['post_id']))? (int) $options['post_id'] : null; // current page | |
if($current_page && ($rule['operator'] === "!=") && isset( $special[$rule['value']] ) ) { | |
$match = ($special[$rule['value']] !== $current_page ); | |
}elseif( $current_page && ($rule['operator'] === "==") && isset( $special[$rule['value']] ) ){ | |
$match = ($special[$rule['value']] === $current_page ); | |
} | |
return $match; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example how it look like