Friday, April 26, 2024
HomeWordPress Developmentsuperior customized fields - Updating publish object through ACF breaks front-end

superior customized fields – Updating publish object through ACF breaks front-end


I’ve arrange a working WP Insert publish, that loops via my API name.

I’m then updating my ACF publish object subject which is profitable however…
I’m encountering a problem after I replace my ACF publish object subject through this insert post-call, it breaks the entrance finish of the web site.

This does not occur after I use a Textual content or Choose ACF subject, ONLY with the publish object.

I’m questioning if anybody else has encountered this difficulty, or if there’s something I can do to unravel it.

Respect your assist!

enter image description here

My Code Beneath:

foreach($AllStaff[0] as $employees) {

        $staff_slug = sanitize_title($staff->fields->Title . '-' . $staff->id);
        $staff_title = $staff->fields->Title;
        $staff_active = $staff->fields->Lively;
        $retailer = $staff->fields->field_3;
        //Will get location object from customized publish sort
        foreach($places as $location) {
            if($retailer === $location->post_title) {
                $locationObject = get_post( $location->ID );
            }
        };
        $positions = $staff->fields->field_2;
        $specialties = $staff->fields->Specialties;
        $bio = $staff->fields->field_1;
        //Up to date Date/Time
        $updatedISO = $staff->lastModifiedDateTime;
        //Picture
        $ImageJSON = $staff->fields->Picture;
        $ImageArray = json_decode($ImageJSON);
        $ImageUrl = $ImageArray->serverUrl . $ImageArray->serverRelativeUrl;

        $existing_staff = get_page_by_path($staff_slug, 'OBJECT', 'employees');

        remove_action('wp_ajax_get_staff_from_sharepoint', 'get_staff_from_sharepoint');

        if( ! empty($staff_active) ) {
            
            $inserted_staff = wp_insert_post([
                'post_name' => $staff_slug,
                'post_title' => $staff_title,
                'post_content' => $bio,
                'post_type' => 'staff',
                'post_status' => 'publish'
            ]);

            if(is_wp_error($inserted_staff || $inserted_staff === 0)) {
                proceed;
            };

            $staff_fields = [
                //Store
                'field_5de70e86a0c61' => $locationObject,
                //Postion
                'field_5de848c06ba3b' => $positions,
                //Specialties - select
                'field_5de8a44c6d194' => $specialties,
                //Updated
                'field_633bf606437c5' => $updatedISO,
            ];

            // Assign ACF fields with values
            foreach($staff_fields as $key => $identify) {
                update_field($key, $identify, $inserted_staff);
            }

            // Set featured picture from URL through FIFU plugin
            fifu_dev_set_image($inserted_staff, $ImageUrl);

            }

        add_action('wp_ajax_get_staff_from_sharepoint', 'get_staff_from_sharepoint');

    };

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments