Support

Account

Home Forums Bug Reports wp_insert_post && update_field

Solved

wp_insert_post && update_field

  • Hi guys,

    I found a strange bug. I add posts with the wp_insert_port()-function. After that I added the values of the required fields with update_field().
    That work’s, all posts have their values and the database is also correct.

    But if you use the values of the fields for example in the frontend, it doesn’t work! You have to push the Update-Button in the backend for each post. After that all works fine.

    A better solution is to use the add_post_meta()-function instead update_field(). This will fix this strange bug and you can use the values whereever you want.

  • This is because there is no field key reference stored in the database for the field. Most basic fields that store only a text string will work, but most of the advance type fields, anything not listed under “Basic” when creating the field will probably not work with only a few exceptions.

    In order to use update field for new posts where ACF fields do not yet exist you must use the field key when calling update field instead of the field name. This is explained in the update_field() documentation https://www.advancedcustomfields.com/resources/update_field/

  • Hi John, The update_field documentation does not address ACF taxonomy field types. I have used the update_field() call with using the ACF taxonomy field key, but I still need to click the Update button through the admin UI in order to link the ACF taxonomy field value to the WP taxonomy value. Could you please provide a code example for taxonomy values.

    $dl_ploidy = ‘field_586131d916252’;
    $dl_ploidy_value = $seedlingploidy;
    update_field($dl_ploidy, $dl_ploidy_value, $post_id);

    using the code above, the value is saved to the correct field, and is viewable through the admin interface, but not on front end output that displays the corresponding wp taxonomy value. Once I click update on the admin post screen, the value is displayed in the front end output. Also, if I follow this call with wp_set_post terms, or wp_set_object_terms, I get the same behavior. An example would be really great. Thanks!

  • Does the taxonomy field in question have the load terms and save terms options set to Yes?

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

The topic ‘wp_insert_post && update_field’ is closed to new replies.