Home Forums Front-end Issues Accessing all Advanced Custom Field checkbox values


Accessing all Advanced Custom Field checkbox values

  • Is it possible to access all values for an ACF Checkbox field available in the ‘Choices’ field settings?

    Choices field settings

    Using get_field_object / get_field etc seem to only return results for a single post and haven’t been able to access settings values via the ‘options’ argument.

    Many thanks in advance,

  • You can use like this:

    //Get all items from fieldname
    $fieldname = get_field('fieldname', $current_user);
    $id = get_the_ID();
    $field = get_field_objects($current_user);
    $field_name = $field["field_name"]["name"];
    if( $field ){
      foreach ( $field["fieldname"]['choices'] as $key => $value) {
    							if ( in_array( $key, $newsletter  ) ) {
    								$checked = 'checked';
    								$checked = '';
    							echo '<p class="field"><input type="checkbox" '.$checked.' name="'.$field_name.'" value="'.$key.'">'.$value.'</p>';
  • Passing in a user ID would lead to the same inconsistencies as using a post ID in my use case. I can’t assume that each author would have used each of the values of the ACF checkbox to populate the filter dropdown.

    Additionally, this would fail in the context where a user is not logged in, or is a user without an actual author account – hence why I am hoping to access the ‘Options’ page or DB reference for the field.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Accessing all Advanced Custom Field checkbox values’ is closed to new replies.