All Topics
Support custom ACF date field values for filtering
Hey guys,
I noticed that if using a custom stored value for ACF datepicker fields, filtering is not possible by this field.
Is there a way to change this behavior with some hooks?
We store all ACF date field values as timestamps for improved flexibility. Thus we’d need to adjust how AC is handling this as well.
For now, we only managed to adjust the date display in the column like this:
// show correct date in columns view due to acf date values being stored as timestamps
add_filter( 'ac/column/value', function ( $value, $id, $column ) {
if( get_post_type($id) !== 'event' ) {
return $value;
}
if ( $column instanceof ACA\ACF\Column ) {
$acf_field = $column->get_acf_field(); // Gets an ACF object
$acf_type = $column->get_acf_field_option( 'type' ); // Get the ACF field type
if( 'date_time_picker' === $acf_type ) {
$value = date_i18n( $acf_field['display_format'], get_field($acf_field['key'], $id, false) );
}
}
return $value;
}, 10, 3 );
Note the additional ACF get_field()
query since the $value
param has no valid value. BTW: Is there still some kind of ‘raw’ filter hook to get the exact value from the database here as in version 3?
Thanks in advance,
Daniel
You must be logged in to reply to this topic.