Custom Fields
Re-Envisioned
Support General save Text List field using update post meta

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 7 months, 3 weeks ago.

  • Creator
    Topic
  • #11722
    Resolved
    clientservices
    Participant

    Dear Support,

    i have a text_list in my admin custom post type and i am trying to set the values using update_post_meta.

    this is my field:

    array(
                        'id' => $prefix . 'address',
                        'type' => 'text_list',
                        'name' => esc_html__( 'Postal Address', 'nw' ),
                        'options' => array(
                            'address_1' => 'Address Line 1',
                            'address_2' => 'Address Line 2',
                        ),
                    ),

    $prefix = 'pph-';
    update_post_meta($applicantID, $prefix . "address", 'one');

    i tried the above and it sets the value for both fields. address_1 and address_2

    i also tried below with no avail
    update_post_meta($applicantID, $prefix . "address[]", 'one');
    update_post_meta($applicantID, $prefix . "address[address_1]", 'one');

    thank you.

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #11748

    Anh Tran
    Keymaster

    Hello,

    text_list save data in multiple rows in the database. So, using update_post_meta might removes all existing values.

    I’d suggest using add_post_meta instead:

    add_post_meta($applicantID, $prefix . "address", 'one', false);
    add_post_meta($applicantID, $prefix . "address", 'two', false);

    Notice the last parameter, it must be set to false. For more info, please see the Codex.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.