Skip to content

Instantly share code, notes, and snippets.

@isuke01
Last active Sep 7, 2018
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@isuke01 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