Home › Forums › General Issues › Get fields wont return my group fields unless i republish the posts
Hi,
So my problem is quite simple, im doing a dynamic update_field on a custom post type. Everything is working fine. But when i want to use get_fields( $post_id ), it returns NULL. If i go on the post from admin dashboard, i see the updated fields like its supposed to and if i just update the post without changing anything, i then go back to my get_fields( $post_id) function and it works.
Here’s the code from my dynamic update process :
// Booking info
update_field( 'booking_info_name', $client_data['personnal']['name'], $get_booking->ID );
update_field( 'booking_info_email', $client_data['personnal']['email'], $get_booking->ID );
update_field( 'booking_info_phone', $client_data['personnal']['phone'], $get_booking->ID );
update_field( 'booking_info_adults', $booking_object['adults'], $get_booking->ID );
update_field( 'booking_info_teens', $booking_object['teens'], $get_booking->ID );
update_field( 'booking_info_childs', $booking_object['childs'], $get_booking->ID );
// Transaction info
update_field( 'booking_transaction_date', $client_data['transaction']['date'], $get_booking->ID );
update_field( 'booking_transaction_booking_objects', $client_data['transaction']['booking_objects'], $get_booking->ID );
update_field( 'booking_transaction_total', $client_data['transaction']['total'], $get_booking->ID );
update_field( 'booking_transaction_total_deposit', $client_data['transaction']['total_deposit'], $get_booking->ID );
update_field( 'booking_transaction_coupons', $client_data['transaction']['applied_coupons'], $get_booking->ID );
update_field( 'booking_transaction_total_discount', $client_data['transaction']['total_discount'], $get_booking->ID );
As i said, everything is saved and working but for some reason its like not “published” until i go on the post and do it myself…
Any solution?
When updating fields that do not already have values stored in the DB you need to use the field key when updating and not the field name. This is covered in the documentation https://www.advancedcustomfields.com/resources/update_field/
You must be logged in to reply to this topic.
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.