Home › Forums › General Issues › ACF posts orderby not working correct › Reply To: ACF posts orderby not working correct
The special thing is, the nummeric field is a field which is generated out of 2 date fields. I set the start and the endtime of the run and when i save the post (backend frontend) the field contest_endtime is calculated automatically by a function. This is saved in my functions.php:
function save_contest_post( $post_id ) {
// vars
$fields = $_POST['acf'];
// get custom fields (field group exists for content_form)
$skipper = sanitize_title(get_field('contest_skipper', $post_id));
$yardstick = get_field('contest_yardstick', $post_id);
$startdate = get_field('contest_startdate', $post_id);
$starttime = get_field('contest_starttime', $post_id);
$startdatetime = $startdate .' '. $starttime;
$changetime = get_field('contest_changetime',$post_id);
$changedatetime = $startdate .' '. $changetime;
$goaltime = get_field('contest_goaltime',$post_id);
$goaldatetime = $startdate .' '. $goaltime;
$startdatetime = date_create_from_format('d.m.Y H:i:s', $startdatetime);
$changedatetime = date_create_from_format('d.m.Y H:i:s', $changedatetime);
$goaldatetime = date_create_from_format('d.m.Y H:i:s', $goaldatetime);
$interimTime = ($changedatetime->getTimestamp() - $startdatetime->getTimestamp()) * $yardstick;
$endTime = ($goaldatetime->getTimestamp() - $startdatetime->getTimestamp()) * $yardstick;
update_field('contest_middletime', $interimTime, $post_id);
update_field('contest_endtime', $endTime, $post_id);
wp_update_post(array( 'ID' => $post_id, 'post_title' => $skipper ));
}
add_action('acf/save_post', 'save_contest_post', 20);
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.