Home Forums General Issues Field name vs field key while update_post()


Field name vs field key while update_post()

  • Hello there. I’m working on migration tool for huge project (500K+ post types) and everything was fine till I found that using field name isn’t perfect solution as in the backend (post edit screen) the values where updated, but on the frontend not always. I found that it’s generally better to use field keys, but the quick question from me is: should I do something like:

    // Check if there is a second row in 'nr_tel'
    if (isset($nr_tel_values[1])) {
    // Get the second row's 'numer' value
    $phone_additional = $nr_tel_values[1]['numer'];
    // Update the 'phone_additional' field with the 'numer' value
    update_field('phone_additional', $phone_additional, $post_id);
    // Update the 'phone_additional' field by it's field key with the 'numer' value
    update_field('field_64ac308220c5a', $phone_additional, $post_id);

    Is that good way or should I use update_field() just once with field key?

    Best regards, Paul

  • Use only the field key, there is no need to update the field twice, this will just slow down performance.

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

You must be logged in to reply to this topic.