jchristopher / attachments

[WordPress Plugin] Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
wordpress.org/extend/plugins/attachments/
GNU General Public License v2.0
241 stars 78 forks source link

Select element: Array to string conversion error #149

Closed bigmike7801 closed 6 years ago

bigmike7801 commented 9 years ago

I have followed the instructions on how to Create Custom Instances and it appears that the select field cause the error Notice: Array to string conversion in /srv/www/wordpress-default/wp-includes/general-template.php on line 3099.

I only get the error however if I have something selected within that form.

If you inspect the DOM inside of a post you can see the error.

Here is my code:

function story_attachments( $attachments ){
  $args = array(
    'label'         => 'Story Carousel',
    'post_type'     => array( 'post', 'page' ),
    'filetype'      => null,  // no filetype limit
    'button_text'   => 'Attach Files',
    'modal_text'    => 'Attach',

    /**
     * Fields for the instance are stored in an array. Each field consists of
     * an array with three keys: name, type, label.
     *
     * name  - (string) The field name used. No special characters.
     * type  - (string) The registered field type.
     *                  Fields available: text, textarea
     * label - (string) The label displayed for the field.
     */

    'fields'        => array(
        array(
            'name'  => 'title',                          // unique field name
            'type'  => 'text',                           // registered field type
            'label' => __( 'Title', 'attachments' ),     // label to display
            'default'   => 'title',                       // default value upon selection
        ),
        array(
            'name'      => 'caption',                       // unique field name
            'type'      => 'wysiwyg',                       // registered field type
            'label'     => __( 'Caption', 'attachments' ),  // label to display
            'default'   => 'caption',                       // default value upon selection
        ),

        array(
            'name'  => 'byline',                        // unique field name
            'type'  => 'text',                          // registered field type
            'label' => 'Byline',                        // label to display
            'default'   => 'post_author',                       // default value upon selection
        ),
        array(
            'name'  => 'credit',                        // unique field name
            'type'  => 'text',                          // registered field type
            'label' => 'Credit',                        // label to display
            'default'   => 'description',                       // default value upon selection
        ),
        array(
            'name'      => 'distribute',                        // unique field name
            'type'      => 'select',                            // registered field type
            'label'     => 'Make available for Purchase',       // label to display
            'meta'      => array(                               // field-specific meta as defined by field class
                            'allow_null'    => true,            // allow null value? (adds 'empty' <option>)
                            'multiple'      => true,            // multiple <select>?
                            'options'       => array(           // the <option>s to use
                                  '0'     => 'No',
                                  '1'     => 'Yes',
                              )
                          ),
        ),
    ),

  );

  $attachments->register( 'story_carousel_attachments', $args ); // unique instance name
}

Here's the output of that element when you inspect the DOM:

<div class="attachment-field attachment-field-story_carousel_attachments">
    <select name="attachments[story_carousel_attachments][559ef7798b700][fields][distribute][]" id="attachments[story_carousel_attachments][559ef7798b700][fields][distribute]559ef7798b700" class="attachments attachments-field attachments-field-attachments[story_carousel_attachments][559ef7798b700][fields][distribute] attachments-field-attachments[story_carousel_attachments][559ef7798b700][fields][distribute]559ef7798b700" multiple="">

        Notice: Array to string conversion in /srv/www/wordpress-default/wp-includes/general-template.php on line 3099
        <option value="0" selected="">No </option>

        Notice: Array to string conversion in /srv/www/wordpress-default/wp-includes/general-template.php on line 3099
        <option value="1">Yes </option>
    </select>
</div>
jchristopher commented 6 years ago

Hello, given the age of this Issue I'm going to mark it as Closed but if this is still a problem please comment here!

bigmike7801 commented 6 years ago

Time does not heal all wounds.

jchristopher commented 6 years ago

Hi @bigmike7801 — are you still trying to work with Attachments?