Home › Forums › Front-end Issues › Display ACF fields that are modified by filters › Reply To: Display ACF fields that are modified by filters
When I dump out the value for the $field
the choices are are the original values that was inserted into the field, and not the filtered values that are being brought in dynamically.
I am not sure if it matters or not, but I am trying to display the fields as custom columns in my custom post type.
function custom_column( $column, $post_id ) {
switch ( $column ) {
case 'custom_title':
$field = get_field_object( 'custom_field) );
$value = get_post_meta( $post_id, 'custom_field', true );
echo $field['choices'][ $value ]; //This returns an Undefined index and the index value is not in the $field variable.
break;
default:
break;
}
}
add_action( 'manage_custom_posts_custom_column', 'custom_column', 10, 2);
And to load my custom field:
function acf_custom_field_choices( $field ) {
// reset choices
$field['choices'] = array();
$args = array(
'post_type' => 'custom_post_type',
'parent' => 0
);
$pages = get_pages( $args );
foreach ( $pages as $page ) {
// vars
$value = $page->post_name;
$label = $page->post_title;
// append to choices
$field['choices'][ $value ] = $label;
}
// return the field
return $field;
}
add_filter('acf/load_field/name=custom_field','acf_custom_field_choices', 10, 1);
I am not sure if my loading sequence or priority of the filter and/or action matters.
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.