Home › Forums › Backend Issues (wp-admin) › Only Display Field Group if Page is Password Protected › Reply To: Only Display Field Group if Page is Password Protected
I was able to solve this with the following code:
/* SHOW FIELD SET ON PASSWORD PROTECTED PAGES */
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
$choices['Post']['visibility'] = 'Post Visibility';
return $choices;
}
add_filter('acf/location/rule_values/visibility', 'acf_location_rules_values_visibility');
function acf_location_rules_values_visibility( $choices ) {
//var_dump($choices);
$choices['password'] = 'Password Protected';
return $choices;
}
add_filter('acf/location/rule_match/visibility', 'acf_location_rules_match_visibility', 10, 3);
function acf_location_rules_match_visibility( $match, $rule, $options )
{
$the_post = get_post($options->post_id);
$pw = $the_post->post_password;
if(isset($pw)){
if(!empty($pw)){
$match = true;
}
}else{
$match = false;
}
return $match;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.