I also tried with:
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'contest',
'meta_key' => 'contest_endtime',
'orderby' =>'meta_value',
'order' => 'ASC'
));
Yes its correct, its a time difference multyplied by a number. This is something like a handycap in golf so that different boat can start in the same competition. Why is this not working? I get the numbers into the field in wordpress, i can see them in the backend and the output fields. It should just order by these number which is a nummeric afc field.
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);
No the field is a nummeric field. Just normal nummeric values without any decimals or something.
Hey James…. sorry this gets embarrasing for me. But i still have no idea. I need to write a new user into my user database. The fields firstname and lastname exist without acf. I dont know how to create something like:
<?php
acf_form(array(
'user_id' => 'new_user',
'user_lastname' => 'formfield_lastname',
'user_firstname' => 'formfield_firstname',
'user_company_acf' => 'formfield_company'
?>
Im so sorry… but this function is essential for my website.
Hi James!
Sorry but im no step further. When i use the code like posted above on my website:
<?php
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'new_post' => array(
'post_type' => 'contact_form',
'post_status' => 'publish'
),
'return' => home_url('contact-form-thank-you'),
'submit_value' => 'Send'
));
?>
I just get a form with a title and a wysiwyg-box. The form i need should have at least the fields user-firstname, user-lastname and some custom fields i added to the users.
Sorry but i really have no idea how to create that. Should i give you access to my wp backend?
Thanks Pascal
Hey James!
Thanks for your help, i tried to figure out how this works but im no step further. To add a new post i add the following code to my index.php. I dont know how this should look when i try to add a new user?
Sorry and thanks for your help!
<?php
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'new_post' => array(
'post_type' => 'contact_form',
'post_status' => 'publish'
),
'return' => home_url('contact-form-thank-you'),
'submit_value' => 'Send'
));
?>
Thank you so much for your help! That gives me an idea how to solve that problem.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.