Support

Account

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;
    }