Home › Forums › General Issues › ACF field that returns value, based on date formula (years since ACF date field) › Reply To: ACF field that returns value, based on date formula (years since ACF date field)
add_filter('acf/format_value/name=years_employed', 'calculate_years_employed', 20, 3);
function calculate_years_employed($value, $post_id, $field) {
// don't really care what the value is
$start_date = get_field('start_date', $post_id);
$value = calculate how long from start date...
return $value;
}
this has not been tested at all, but I am pretty sure that the field I’m calling “years_employed” and be a text field with no value at all that is never stored. Because we are ignoring whatever value this field might have and generating a new formatted value.
This could also be accomplished with an acf/load_value filter.
Just one note. In order to use either of these filters with the field name the field must actually exist in the DB event if the field has no value.
If you wanted, for completeness, you could create and acf/save_post filter that would automatically populate the value, but like I said, I think it would work fine using a text field where an empty value is stored in the DB.
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.