Custom Fields
Re-Envisioned
Support General Field type 'key_value' gives notice: array to string conversion

  • Creator
    Topic
  • #16906
    info@yard.nl
    Participant

    Hello,

    I’ve created a metabox field with the type ‘key_value’. when viewing my metabox field it displays an notice: Notice: Array to string conversion in /Users/User/Desktop/Development/project-kwintes-portal/htdocs/wp-content/plugins/meta-box/inc/fields/key-value.php on line 101. This only happens while creating a new page.

    Here is an example of my code:

    
    [
        'id'          => "{$keyName}_scroll_tabs",
        'name'        => __('Vul de titel in en het ID in van het element waar naartoe gescrollt dient te worden.', 'fusion'),
        'type'      => 'key_value',
        'placeholder' => ['key' => 'Titel', 'value' => 'Anchor ID'],
        'multiple'      => true,
        'clone'       => true,
        'add_button' => __('Set toevoegen', 'fusion')
    ]
    

    When I create the page en publish it the Notice is gone.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #16929
    Anh Tran
    Keymaster

    I’ve just tried with the code and don’t see the notice. Can you check that again?

    #17076
    info@yard.nl
    Participant

    As college of topic starter, I dug a bit deeper, and found that adding a default, did help:

    
    [
        'id'          => "{$keyName}_scroll_tabs",
        'name'        => __('Vul de titel in en het ID in van het element waar naartoe gescrollt dient te worden.', 'fusion'),
        'type'      => 'key_value',
        'placeholder' => ['key' => 'Titel', 'value' => 'Anchor ID'],
        'std' => ['key' => ''],
        'multiple'      => true,
        'clone'       => true,
        'add_button' => __('Set toevoegen', 'fusion')
    ]
    

    Maybe it’s useful to add a default value of an empty string.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.