during page load, the $options is an array with zero elements. so I modified my code and now it works.
add_filter('acf/location/rule_match/post_category', 'acf_location_rules_match_post_category', 10, 3);
function acf_location_rules_match_post_category( $match, $rule, $options )
{
$current_cat = $options['post_category']; // array, user selection
$rule_cat_id = (int) $rule['value']; // numeric, rule
global $pagenow;
if (count($current_cat)==0 && $pagenow=='post.php'){
// if we're editing post and not adding a new post
$current_cat= wp_get_post_categories($options["post_id"]);
}
if($rule['operator'] == "<=")
{
$match = false;
$match = in_array($rule_cat_id, $current_cat); //check if main cat
if (!$match){
// check the subcategories instead so first get the subcats
$args=array(
'child_of'=>$rule_cat_id,
'hide_empty'=>0
);
$subcats = get_categories($args);
foreach ($subcats as $subcat){
if (in_array($subcat->term_id, $current_cat))
{
$match = true;
break;
}
}
}
}
return $match;
}
hi @elliot, if I just flag $match as true, the ACF fields appears on the page meaning it gets run during page load but somehow, the rule didn’t match.
is there anyway I can see what is the content of the $options array during page load?