Home › Forums › ACF PRO › acf/load_field Filter not working in ACF Pro › Reply To: acf/load_field Filter not working in ACF Pro
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;
}
}
?>
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.