Skip to content

Instantly share code, notes, and snippets.

@isuke01
Last active September 7, 2018 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isuke01/51f742fa15cb3e3da9f74e9de7fd5195 to your computer and use it in GitHub Desktop.
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)
<?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;
}
@isuke01
Copy link
Author

isuke01 commented Aug 20, 2018

edit_field_group_ hef_konfressurs _wordpress
Example how it look like

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