Support

Account

Forum Replies Created

  • Thanks for your explanation John!

    However I think it’s not my problem: I never call get_field() on update/create post process, I call get_field() on page reload AFTER the process is completely finished (after several seconds, and after several reloads ^^). And I call wp_post_update() BEFORE any ACF update_field() (but there are ACF get_field() calling before wp_post_update() to populate data).

    To briefly explain:
    1. I call Airtable API (a Database/Excel like) to retrieve new data
    2. Retrieve the WP Post from WP ID stored in Airtable
    3. Populate Company PHP Object with existing data in WP (use get_field())
    4. Update data in Company PHP Object with new data retrieved in Airtable (custom PHP)
    5. Commit data in WP from new Company PHP Object with wp_update_post() and (only after) update_field().
    6. I go to the Company Page Edition in WP Back Office: All data are updated!
    7. I check in database with an SQL Query: All data are updated correctly
    8. I go to the Company Page in Front End to view modifications (so the PHP process is completely finished) by page reload (several reloads to be sure ^^), but nothing changed, old data are displayed :'( (no cache issue).

    I think my issue doesn’t covered by your explanation, but I could be wrong 😶

    I am currently developing a new getField() function, but if you have a secret sauce… 😁

  • Sooooo I have a workaround:

    remove_action('post_updated', 'wp_save_post_revision');
    
    ...
    wp_update_post($postData);
    ...
    update_field('field_XYZ123', $value, $post_id);
    ...
    
    add_action('post_updated', 'wp_save_post_revision');

    And it works apparently, on the other hand we have no revision during the post update…

    So the real question (I think) is the following:

    Why get_field() called in WP theme doesn’t retrieve the same Post ID than the one retrieved from the Back Office?

  • Ok I just searched in ACF code and I can see that acf_get_valid_post_id() executed in get_field() function to get the Post ID return a revision of the post, not the real ID… I don’t understand why but there must be a good reason ^^

    I continue my research…

  • Hi John, thanks for your answer!

    I use only field keys and I use several levels of nested fields, for example:

    `
    const ACF_ID_COMPANY_IDENTITY = ‘field_5d5e603dbfb7b’;
    const ACF_ID_COMPANY_IDENTITY_LOGO = ‘field_5d5e60cbbfb7d’;
    const ACF_ID_COMPANY_IDENTITY_CREATION_YEAR = ‘field_5d5e6279bfb80’;
    const ACF_ID_COMPANY_IDENTITY_HEADER_ILLU = ‘field_5d5e612abfb7e’;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU = ‘field_5d5e61e3bfb7f’;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA = ‘field_5dc95f49358a6’ . ‘_’ . ACF_ID_GLOBAL_MEDIA;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE = ACF_ID_GLOBAL_MEDIA_TYPE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE = ACF_ID_GLOBAL_MEDIA_IMAGE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO = ACF_ID_GLOBAL_MEDIA_VIDEO;

    // Logo
    if ($company->hasLogo() && $company->getLogo()->hasId()) {
    $identity[ACF_ID_COMPANY_IDENTITY_LOGO] = $company->getLogo()->getId();
    }

    // Creation Year
    if ($company->hasCreationYear()) {
    $identity[ACF_ID_COMPANY_IDENTITY_CREATION_YEAR] = $company->getCreationYear();
    }

    // — /General

    // — Illustrations
    // Header Illustration
    if ($company->hasHeaderMedia() && $company->getHeaderMedia()->hasId()) {
    $identity[ACF_ID_COMPANY_IDENTITY_HEADER_ILLU] = $company->getHeaderMedia()->getId();
    }

    // Main Illustration
    if ($company->hasMainMedia() && ($company->getMainMedia()->hasId() || $company->getMainMedia()->hasSrc())) {
    $mainMedia = [];

    if ($company->getMainMedia()->isImage()) {
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_IMAGE;
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE] = $company->getMainMedia()->getId();
    }

    if ($company->getMainMedia()->isVideo()) {
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_ TYPE] = Media::ACF_IS_VIDEO;
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO] = $company->getMainMedia()->getSrc();
    }

    $identity[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU][ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA] = $mainMedia;
    }
    // — /Illustrations

    // Update IDENTITY
    if (!empty($identity)) {
    update_field(ACF_ID_COMPANY_IDENTITY, $identity, $postId);
    }
    `

    So here what do you think I should do? Use add_row() instead of arrays? Use update_sub_field() instead of update_field() on all $identity variable?

    I admit that I don’t understand why this is a problem… Is it really impossible to take the problem the other way by forcing ACF to retrieve the data in the database that was just put in? Because they are present in the database, these data, and we can see them clearly in the backoffice, why we don’t retrieved them in the frontoffice via get_field()? I do not understand… :/

  • Hi John, thanks for your answer!

    I use only field keys and I use several levels of nested fields, for example:

    
    const ACF_ID_COMPANY_IDENTITY = 'field_5d5e603dbfb7b';
    const ACF_ID_COMPANY_IDENTITY_LOGO = 'field_5d5e60cbbfb7d';
    const ACF_ID_COMPANY_IDENTITY_CREATION_YEAR = 'field_5d5e6279bfb80';
    const ACF_ID_COMPANY_IDENTITY_HR_MAIL = 'field_5e022ff49af2b';
    const ACF_ID_COMPANY_IDENTITY_TURNOVER = 'field_5d5e6c44bfb88';
    const ACF_ID_COMPANY_IDENTITY_HEADER_ILLU = 'field_5d5e612abfb7e';
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU = 'field_5d5e61e3bfb7f';
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA = 'field_5dc95f49358a6' . '_' . ACF_ID_GLOBAL_MEDIA;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE = ACF_ID_GLOBAL_MEDIA_TYPE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE = ACF_ID_GLOBAL_MEDIA_IMAGE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO = ACF_ID_GLOBAL_MEDIA_VIDEO;
    
    // Logo
    if ($company->hasLogo() && $company->getLogo()->hasId()) {
        $identity[ACF_ID_COMPANY_IDENTITY_LOGO] = $company->getLogo()->getId();
    }
    
    // Creation Year
    if ($company->hasCreationYear()) {
        $identity[ACF_ID_COMPANY_IDENTITY_CREATION_YEAR] = $company->getCreationYear();
    }
    
    // Global HR Mail Address
    if ($company->hasGlobalHrMailAddress()) {
        $identity[ACF_ID_COMPANY_IDENTITY_HR_MAIL] = $company->getGlobalHrMailAddress();
    }
    
    // Turnover
    if ($company->hasTurnover()) {
        $identity[ACF_ID_COMPANY_IDENTITY_TURNOVER] = $company->getTurnover();
    }
    
    // -- /General
    
    // -- Illustrations
    // Header Illustration
    if ($company->hasHeaderMedia() && $company->getHeaderMedia()->hasId()) {
        $identity[ACF_ID_COMPANY_IDENTITY_HEADER_ILLU] = $company->getHeaderMedia()->getId();
    }
    
    // Main Illustration
    if ($company->hasMainMedia() && ($company->getMainMedia()->hasId() || $company->getMainMedia()->hasSrc())) {
        $mainMedia = [];
    
        if ($company->getMainMedia()->isImage()) {
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_IMAGE;
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE] = $company->getMainMedia()->getId();
        }
    
        if ($company->getMainMedia()->isVideo()) {
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_ TYPE] = Media::ACF_IS_VIDEO;
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO] = $company->getMainMedia()->getSrc();
        }
    
        $identity[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU][ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA] = $mainMedia;
    }
    // -- /Illustrations
    
    // Update IDENTITY
    if (!empty($identity)) {
        update_field(ACF_ID_COMPANY_IDENTITY, $identity, $postId);
    }
    

    So here what do you think I should do? Use add_row() instead of arrays? Use update_sub_field() instead of update_field() on all $identity variable?

  • Hi John, thanks for your answer!

    I use only field keys and I use several levels of nested fields, for example:

    `
    const ACF_ID_COMPANY_IDENTITY = ‘field_5d5e603dbfb7b’;
    const ACF_ID_COMPANY_IDENTITY_LOGO = ‘field_5d5e60cbbfb7d’;
    const ACF_ID_COMPANY_IDENTITY_CREATION_YEAR = ‘field_5d5e6279bfb80’;
    const ACF_ID_COMPANY_IDENTITY_HR_MAIL = ‘field_5e022ff49af2b’;
    const ACF_ID_COMPANY_IDENTITY_TURNOVER = ‘field_5d5e6c44bfb88’;
    const ACF_ID_COMPANY_IDENTITY_HEADER_ILLU = ‘field_5d5e612abfb7e’;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU = ‘field_5d5e61e3bfb7f’;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA = ‘field_5dc95f49358a6’ . ‘_’ . ACF_ID_GLOBAL_MEDIA;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE = ACF_ID_GLOBAL_MEDIA_TYPE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE = ACF_ID_GLOBAL_MEDIA_IMAGE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO = ACF_ID_GLOBAL_MEDIA_VIDEO;

    // Logo
    if ($company->hasLogo() && $company->getLogo()->hasId()) {
    $identity[ACF_ID_COMPANY_IDENTITY_LOGO] = $company->getLogo()->getId();
    }

    // Creation Year
    if ($company->hasCreationYear()) {
    $identity[ACF_ID_COMPANY_IDENTITY_CREATION_YEAR] = $company->getCreationYear();
    }

    // Global HR Mail Address
    if ($company->hasGlobalHrMailAddress()) {
    $identity[ACF_ID_COMPANY_IDENTITY_HR_MAIL] = $company->getGlobalHrMailAddress();
    }

    // Turnover
    if ($company->hasTurnover()) {
    $identity[ACF_ID_COMPANY_IDENTITY_TURNOVER] = $company->getTurnover();
    }

    // — /General

    // — Illustrations
    // Header Illustration
    if ($company->hasHeaderMedia() && $company->getHeaderMedia()->hasId()) {
    $identity[ACF_ID_COMPANY_IDENTITY_HEADER_ILLU] = $company->getHeaderMedia()->getId();
    }

    // Main Illustration
    if ($company->hasMainMedia() && ($company->getMainMedia()->hasId() || $company->getMainMedia()->hasSrc())) {
    $mainMedia = [];

    if ($company->getMainMedia()->isImage()) {
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_IMAGE;
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE] = $company->getMainMedia()->getId();
    }

    if ($company->getMainMedia()->isVideo()) {
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_VIDEO;
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO] = $company->getMainMedia()->getSrc();
    }

    $identity[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU][ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA] = $mainMedia;
    }
    // — /Illustrations

    // Update IDENTITY
    if (!empty($identity)) {
    update_field(ACF_ID_COMPANY_IDENTITY, $identity, $postId);
    }
    `

    So here what do you think I should do? Use add_row() instead of arrays? Use update_sub_field() instead of update_field() on all $identity variable?

    I admit that I don’t understand why this is a problem… Is it really impossible to take the problem the other way by forcing ACF to retrieve the data in the database that was just put in? Because they are present in the database, these data, and we can see them clearly in the backoffice, why we don’t retrieved them in the frontoffice via get_field()? I do not understand… :/

  • Hi John, thanks for your answer!

    I use only field keys and I use several levels of nested fields, for example:

    `
    const ACF_ID_COMPANY_IDENTITY = ‘field_5d5e603dbfb7b’;
    const ACF_ID_COMPANY_IDENTITY_LOGO = ‘field_5d5e60cbbfb7d’;
    const ACF_ID_COMPANY_IDENTITY_CREATION_YEAR = ‘field_5d5e6279bfb80’;
    const ACF_ID_COMPANY_IDENTITY_HR_MAIL = ‘field_5e022ff49af2b’;
    const ACF_ID_COMPANY_IDENTITY_TURNOVER = ‘field_5d5e6c44bfb88’;
    const ACF_ID_COMPANY_IDENTITY_HEADER_ILLU = ‘field_5d5e612abfb7e’;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU = ‘field_5d5e61e3bfb7f’;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA = ‘field_5dc95f49358a6’ . ‘_’ . ACF_ID_GLOBAL_MEDIA;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE = ACF_ID_GLOBAL_MEDIA_TYPE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE = ACF_ID_GLOBAL_MEDIA_IMAGE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO = ACF_ID_GLOBAL_MEDIA_VIDEO;

    // Logo
    if ($company->hasLogo() && $company->getLogo()->hasId()) {
    $identity[ACF_ID_COMPANY_IDENTITY_LOGO] = $company->getLogo()->getId();
    }

    // Creation Year
    if ($company->hasCreationYear()) {
    $identity[ACF_ID_COMPANY_IDENTITY_CREATION_YEAR] = $company->getCreationYear();
    }

    // Global HR Mail Address
    if ($company->hasGlobalHrMailAddress()) {
    $identity[ACF_ID_COMPANY_IDENTITY_HR_MAIL] = $company->getGlobalHrMailAddress();
    }

    // Turnover
    if ($company->hasTurnover()) {
    $identity[ACF_ID_COMPANY_IDENTITY_TURNOVER] = $company->getTurnover();
    }

    // — /General

    // — Illustrations
    // Header Illustration
    if ($company->hasHeaderMedia() && $company->getHeaderMedia()->hasId()) {
    $identity[ACF_ID_COMPANY_IDENTITY_HEADER_ILLU] = $company->getHeaderMedia()->getId();
    }

    // Main Illustration
    if ($company->hasMainMedia() && ($company->getMainMedia()->hasId() || $company->getMainMedia()->hasSrc())) {
    $mainMedia = [];

    if ($company->getMainMedia()->isImage()) {
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_IMAGE;
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE] = $company->getMainMedia()->getId();
    }

    if ($company->getMainMedia()->isVideo()) {
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_VIDEO;
    $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO] = $company->getMainMedia()->getSrc();
    }

    $identity[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU][ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA] = $mainMedia;
    }
    // — /Illustrations

    // Update IDENTITY
    if (!empty($identity)) {
    update_field(ACF_ID_COMPANY_IDENTITY, $identity, $postId);
    }
    `

    So here what do you think I should do? Use add_row() instead of arrays? Use update_sub_field() instead of update_field() on all $identity variable?

    I admit that I don’t understand why this is a problem… Is it really impossible to take the problem the other way by forcing ACF to retrieve the data in the database that was just put in? Because they are present in the database, these data, and we can see them clearly in the backoffice, why we don’t retrieved them in the frontoffice via get_field()? I do not understand… :/

  • Hi John, thanks for your answer!

    I use only field keys and I use several levels of nested fields, for example:

    const ACF_ID_COMPANY_IDENTITY = 'field_5d5e603dbfb7b';
    const ACF_ID_COMPANY_IDENTITY_LOGO = 'field_5d5e60cbbfb7d';
    const ACF_ID_COMPANY_IDENTITY_CREATION_YEAR = 'field_5d5e6279bfb80';
    const ACF_ID_COMPANY_IDENTITY_HR_MAIL = 'field_5e022ff49af2b';
    const ACF_ID_COMPANY_IDENTITY_TURNOVER = 'field_5d5e6c44bfb88';
    const ACF_ID_COMPANY_IDENTITY_HEADER_ILLU = 'field_5d5e612abfb7e';
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU = 'field_5d5e61e3bfb7f';
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA = 'field_5dc95f49358a6' . '_' . ACF_ID_GLOBAL_MEDIA;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE = ACF_ID_GLOBAL_MEDIA_TYPE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE = ACF_ID_GLOBAL_MEDIA_IMAGE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO = ACF_ID_GLOBAL_MEDIA_VIDEO;
    
    // Logo
    if ($company->hasLogo() && $company->getLogo()->hasId()) {
        $identity[ACF_ID_COMPANY_IDENTITY_LOGO] = $company->getLogo()->getId();
    }
    
    // Creation Year
    if ($company->hasCreationYear()) {
        $identity[ACF_ID_COMPANY_IDENTITY_CREATION_YEAR] = $company->getCreationYear();
    }
    
    // Global HR Mail Address
    if ($company->hasGlobalHrMailAddress()) {
        $identity[ACF_ID_COMPANY_IDENTITY_HR_MAIL] = $company->getGlobalHrMailAddress();
    }
    
    // Turnover
    if ($company->hasTurnover()) {
        $identity[ACF_ID_COMPANY_IDENTITY_TURNOVER] = $company->getTurnover();
    }
    
    // -- /General
    
    // -- Illustrations
    // Header Illustration
    if ($company->hasHeaderMedia() && $company->getHeaderMedia()->hasId()) {
        $identity[ACF_ID_COMPANY_IDENTITY_HEADER_ILLU] = $company->getHeaderMedia()->getId();
    }
    
    // Main Illustration
    if ($company->hasMainMedia() && ($company->getMainMedia()->hasId() || $company->getMainMedia()->hasSrc())) {
        $mainMedia = [];
    
        if ($company->getMainMedia()->isImage()) {
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_IMAGE;
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE] = $company->getMainMedia()->getId();
        }
    
        if ($company->getMainMedia()->isVideo()) {
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_VIDEO;
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO] = $company->getMainMedia()->getSrc();
        }
    
        $identity[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU][ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA] = $mainMedia;
    }
    // -- /Illustrations
    
    // Update IDENTITY
    if (!empty($identity)) {
        update_field(ACF_ID_COMPANY_IDENTITY, $identity, $postId);
    }

    So here what do you think I should do? Use add_row() instead of arrays? Use update_sub_field() instead of update_field() on all $identity variable?

    I admit that I don’t understand why this is a problem… Is it really impossible to take the problem the other way by forcing ACF to retrieve the data in the database that was just put in? Because they are present in the database, these data, and we can see them clearly in the backoffice, why we don’t retrieved them in the frontoffice via get_field()? I do not understand… :/

  • Hi John, thanks for your answer!

    I use only field keys and I use several levels of nested fields, for example:

    const ACF_ID_COMPANY_IDENTITY = 'field_5d5e603dbfb7b';
    const ACF_ID_COMPANY_IDENTITY_LOGO = 'field_5d5e60cbbfb7d';
    const ACF_ID_COMPANY_IDENTITY_CREATION_YEAR = 'field_5d5e6279bfb80';
    const ACF_ID_COMPANY_IDENTITY_HR_MAIL = 'field_5e022ff49af2b';
    const ACF_ID_COMPANY_IDENTITY_TURNOVER = 'field_5d5e6c44bfb88';
    const ACF_ID_COMPANY_IDENTITY_HEADER_ILLU = 'field_5d5e612abfb7e';
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU = 'field_5d5e61e3bfb7f';
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA = 'field_5dc95f49358a6' . '_' . ACF_ID_GLOBAL_MEDIA;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE = ACF_ID_GLOBAL_MEDIA_TYPE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE = ACF_ID_GLOBAL_MEDIA_IMAGE;
    const ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO = ACF_ID_GLOBAL_MEDIA_VIDEO;
    
    // Logo
    if ($company->hasLogo() && $company->getLogo()->hasId()) {
        $identity[ACF_ID_COMPANY_IDENTITY_LOGO] = $company->getLogo()->getId();
    }
    
    // Creation Year
    if ($company->hasCreationYear()) {
        $identity[ACF_ID_COMPANY_IDENTITY_CREATION_YEAR] = $company->getCreationYear();
    }
    
    // Global HR Mail Address
    if ($company->hasGlobalHrMailAddress()) {
        $identity[ACF_ID_COMPANY_IDENTITY_HR_MAIL] = $company->getGlobalHrMailAddress();
    }
    
    // Turnover
    if ($company->hasTurnover()) {
        $identity[ACF_ID_COMPANY_IDENTITY_TURNOVER] = $company->getTurnover();
    }
    
    // -- /General
    
    // -- Illustrations
    // Header Illustration
    if ($company->hasHeaderMedia() && $company->getHeaderMedia()->hasId()) {
        $identity[ACF_ID_COMPANY_IDENTITY_HEADER_ILLU] = $company->getHeaderMedia()->getId();
    }
    
    // Main Illustration
    if ($company->hasMainMedia() && ($company->getMainMedia()->hasId() || $company->getMainMedia()->hasSrc())) {
        $mainMedia = [];
    
        if ($company->getMainMedia()->isImage()) {
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_IMAGE;
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_IMAGE] = $company->getMainMedia()->getId();
        }
    
        if ($company->getMainMedia()->isVideo()) {
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_TYPE] = Media::ACF_IS_VIDEO;
            $mainMedia[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA_VIDEO] = $company->getMainMedia()->getSrc();
        }
    
        $identity[ACF_ID_COMPANY_IDENTITY_MAIN_ILLU][ACF_ID_COMPANY_IDENTITY_MAIN_ILLU_MEDIA] = $mainMedia;
    }
    // -- /Illustrations
    
    // Update IDENTITY
    if (!empty($identity)) {
        update_field(ACF_ID_COMPANY_IDENTITY, $identity, $postId);
    }

    So here what do you think I should do? Use add_row() instead of arrays? Use update_sub_field() instead of update_field() on all $identity variable?

    I admit that I don’t understand why this is a problem… Is it really impossible to take the problem the other way by forcing ACF to retrieve the data in the database that was just put in? Because they are present in the database, these data, and we can see them clearly in the backoffice, why we don’t retrieved them in the frontoffice via get_field()? I do not understand… :/

  • Apparently I found a solution:

    Just add do_action('acf/save_post', $postID); at the end of the script, and that’s all…

  • Hi,

    Anyone found a solution? I’ve the same problem, when I update field after create or update WP Post, I have to resave manually the WP Post to have correct data in get_field(), else I have wrong data display in front-end… :'(

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