Support

Account

Home Forums General Issues Get fields wont return my group fields unless i republish the posts

Helping

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/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.