Support

Account

Home Forums ACF PRO acf/load_field Filter not working in ACF Pro

Solving

acf/load_field Filter not working in ACF Pro

  • In ACF pro
    Following Filter not working kindly explain me what is am doing for that.
    apply_filters(‘acf/load_field’, false, $data[‘field’] );

  • This is not the way you use the load field filter. I can’t tell by looking at this what it is that you’re trying to do.

    The load_field filter is used to alter the settings of a field. This is not something that you apply to a field. https://www.advancedcustomfields.com/resources/acfload_field/

    Can you explain what you are trying to do?

  • We are integrating your ACF Pro plugin with a our search and filter plugin to display Advance Custom Fields in front end.

    we have seen on different forums that this filter does not work in ACF Pro Version.

    We have also share code with you for your better understanding.

    <?php
    function wcf_forms_acf_frontend($form_id = '', $field_id, $data = array() ) {
    
    	if ($data['field'] == '') { echo __('Please, select a field', WORDPRESS_CONTENT_FILTER_LANG); return;}
    
    	$field = apply_filters('acf/load_field', false, $data['field'] );
    	$value_all = 'all';
    	if ($data['filter_select_all'] == 'no') {
    		$value_all = '';
    	}
    
    	$options = array();
    	if (isset($field['choices'])) {
    		if ($data['hide_all'] == 'no') {
    			$options[$value_all] = ($data['change_all_label'] != '') ? $data['change_all_label'] : __('All', WORDPRESS_CONTENT_FILTER_LANG);
    
    		}
    		$options = array_merge($options, $field['choices']);
    	}
    
    	$first_name = 'wcf_acf';
    	$pre_name = $first_name . "[".$field_id."]";
    	$intro = isset($data['intro']) ? 'data-tooltip="'.$data['intro'].'"' : '';
    
    	$label_class = 'wcf-label';
    	$radio_checkbox_layout = 'wcf-horizontal';
    
    	$field_value = apply_filters('wcf_selected_value', $field['default_value'], $first_name, $field_id);
    	$data_reset = str_replace(array("\r"), "", $data['default_value']) ;
    	$data_reset = str_replace(array("\n"), "|", $data_reset) ;
    
    	switch ($field['type']) {
    		case 'select':
    			$field_type = isset($field['multiple']) && $field['multiple'] ? 'multiple' : 'select';
    			$display_type = $field_type == 'multiple' ? 'multiselect' : 'select';
    
    			if (!is_array($field_value)) {
    				$field_value = explode("\n", $field_value);
    			}
    
    			$field_args = array(
    				'type' => $field_type,
    				'name' => $pre_name,
    				'id' => $pre_name . '_select',
    				'value' => $field_value,
    				'options' => $options,
    				'label' => $data['label'],
    				'label_attr' => $intro,
    				'class' => '',
    				'label_class' => $label_class,
    				'wrapper_attr' => 'data-type="'.$data['field_type'].'" data-display="'.$display_type.'" data-reset="'.$data_reset.'"',
    				'before_html' => '<div class="wcf-field-body">',
    				'after_html' => '</div>',
    				'desc' => '',
    			);
    			wcf_forms_field($field_args);
    			break;
    		
    		case 'checkbox':
    
    			if (!is_array($field_value)) {
    				$field_value = explode("\n", $field_value);
    			}
    
    			if ($field['layout'] == 'vertical') {
    				$radio_checkbox_layout = 'wcf-vertical';
    			}
    			$pre_html = '';
    			if ($data['hide_all'] == 'no') {
    				$all_checked = in_array('all', $field_value) ?'checked="checked"' : '';
    				$pre_html = '<div class="wcf-checkbox-wrapper"><input type="checkbox" value="'.$value_all.'" name="'.$pre_name . '[]'.'" class="wcf-checkbox-all" '.$all_checked.'><label class="wcf-checkbox-label"> '.$options[$value_all].'</label></div>';
    				unset($options[$value_all]);
    				if ($all_checked != '') {
    					$field_value = array();
    					foreach ( $options as $key => $default ) {
    						$field_value[] = $key;
    					}
    				}
    			}
    
    			$field_args = array(
    				'type' => 'checkbox',
    				'name' => $pre_name . '[]' ,
    				'id' => $pre_name . '_checkbox',
    				'value' => $field_value,
    				'options' => $options,
    				'label' => $data['label'],
    				'label_attr' => $intro,
    				'label_class' => $label_class,
    				'class' => 'wcf-checkbox-item',
    				'wrapper_class' => $radio_checkbox_layout,
    				'wrapper_attr' => 'data-type="'.$data['field_type'].'" data-display="'.$data['type'].'" data-reset="'.$data_reset.'"',
    				'before_html' => '<div class="wcf-field-body">' . $pre_html,
    				'after_html' => '</div>',
    			);
    
    			wcf_forms_field($field_args);
    			break;
    
    	}
    
    }
    ?>
  • I think what you want to use there is get_field_object() https://www.advancedcustomfields.com/resources/get_field_object/

    $field = get_field_object($data['field'] );

    and in your case since $data['field'] will need to contain the field_key of the selected field. See the 2nd or 3rd section of code under “Usage”

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

The topic ‘acf/load_field Filter not working in ACF Pro’ is closed to new replies.