Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Dale Jacobs

ACF field filter

I see that 4.0 removed “cac/acf/format_acf_value” I have used this filter on 8 sites and trying to change my code to work again with ACF fields. I spent the also hour with “ac/column/value” filter and just failing.

Any way to direct me to the right direction?

Here is my old function that worked before the update.


function my_cac_formatted_acf_value_dates( $value, $acf_field, $id, $originalvalue, $column_object ) {
if ( 'repeater' == $acf_field['type'] ) {
$today = strtotime(date('Ymd'));
$dateclean ='';
foreach($originalvalue as $date){
$start_date = strtotime($date["field_55a00a0df52d2"]);
if( !($start_date>=$today ))continue;
$dateclean .= '<div class="sub_field">'.date("M jS, Y @ g:ia", $start_date).'</div>';
}
$value = $dateclean;
if(empty($value)){
$value = 'Past Event';
};
}
return $value;
}
add_filter( 'cac/acf/format_acf_value', 'my_cac_formatted_acf_value_dates', 10, 5 );

Thanks!

4 years, 5 months ago
Stefan
Developer

Hi Dale,

It’s correct that we now use 1 filter to alter the value for all addons.
Since you have the $column variable to you disposal, you can do any check with this.
The snippet below should give you enough information to change your old filters to the new one.

/**
 * @param $value  string
 * @param $id     integer
 * @param $column AC_Column
 */
function ac_my_acf_test( $value, $id, $column ) {
	if ( 'column-acf_field' == $column->get_type() ) {
		$acf_key = $column->get_setting( 'field' )->get_value(); // Gets the stored ACF key for the stored column
		$acf_field = get_field_object( $acf_key ); // Gets an ACF object based on the ACF Key

		if ( 'repeater' == $acf_field['type'] ) {
			$sub_field_key = $column->get_setting( 'sub_field' )->get_value(); // Get the sub field key stored for the column
			$sub_field = get_field_object( $sub_field_key ); // Gets the ACF sub field object
			
			// Alter the value to your likings
		}
	}

	return $value;
}

add_filter( 'ac/column/value', 'ac_my_acf_test', 10, 3 );
4 years, 5 months ago

You must be logged in to reply to this topic.