Custom Fields
Re-Envisioned
Support General File advanced not rendered correctly

  • Creator
    Topic
  • #26770
    Resolved lucabi
    Participant

    Hi, I’ve tried to add a File advanced field in a custom post type using the same example provided in documentation:

     $meta_boxes[] = array(
                'title'      => 'File',
                'post_types' => $this->post_type_name,
        
                'fields' => array(
                    'id'               => 'file',
                    'name'             => 'File Advanced',
                    'type'             => 'file_advanced',
                
                    // Delete file from Media Library when remove it from post meta?
                    // Note: it might affect other posts if you use same file for multiple posts
                    'force_delete'     => false,
                
                    // Maximum file uploads.
                    'max_file_uploads' => 2,
                
                    // File types.
                    // 'mime_type'        => 'application,audio,video',
                
                    // Do not show how many files uploaded/remaining.
                    'max_status'       => 'false',
                    'multiple' => false
                ),
            );

    but the control is rendered as 7 plain input controls.

    I’m using WordPress 5.7. It makes no difference if I set Gutemberg or classic editor in the post type settings.

    Kind regards, Luca

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #26774
    Long Nguyen
    Moderator

    Hi,

    The fields key is an array of field arrays, it should be

    $meta_boxes[] = array(
        'title'      => 'File',
        'post_types' => 'post',
    
        'fields' => array(
            array(
                'id'               => 'file',
                'name'             => 'File Advanced',
                'type'             => 'file_advanced',
            
                // Delete file from Media Library when remove it from post meta?
                // Note: it might affect other posts if you use same file for multiple posts
                'force_delete'     => false,
            
                // Maximum file uploads.
                'max_file_uploads' => 2,
            
                // File types.
                // 'mime_type'        => 'application,audio,video',
            
                // Do not show how many files uploaded/remaining.
                'max_status'       => 'false',
                'multiple' => false
            ),
            array(
                // another field
            ),
        ),
    );

    Get more details on this basic documentation https://docs.metabox.io/creating-meta-boxes/.

    #26776
    lucabi
    Participant

    Thank you very much, my fault sorry. The fact that something was rendered misled me.

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