Sort fields

Support General Sort fields

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1099
    carassiuscarassius
    Participant

    I have created a group of fields in the side of my CPT and wondering if I can make them sortable without using clone function?

    $meta_boxes[] = array(
            'id'       => 'role',
            'title'    => 'Team Member Info',
            'pages'    => array('team'),
            'context'  => 'side',
            'priority' => 'high',
    
            'fields' => array(            
            
                array(
                    'name'  => 'Position',
                    'desc'  => 'Add the role/position of the team member',
                    'id'    => $prefix . 'position',
                    'type'  => 'text',
                ),
                
                 array(
                    'name'  => 'Phone',
                    'desc'  => 'Add the phone number of the team member',
                    'id'    => $prefix . 'phone',
                    'type'  => 'text',
                ),
                
                array(
                    'name'  => 'Email',
                    'desc'  => 'Add the email adress of the team member',
                    'id'    => $prefix . 'email',
                    'type'  => 'email',
                ),
                
                            
            )
        );
    #1101
    Anh TranAnh Tran
    Keymaster

    I think you can do that with custom JS code. The idea is:

    - Enqueuing a JS file for Add New/Edit pages
    - Call jQueryUI sortable method

    The pseudo-code might look like this:

    add_action( 'admin_enqueue_scripts', function()
    {
        $screen = get_current_screen();
        if ( 'team' == $screen->post_type && 'post' === $screen->base )
        {
            wp_enqueue_script( 'prefix-sort-field', get_theme_directory_uri() . '/js/sort.js', array( 'jquery-ui-sortable' ) );
        }
    } );

    And in sort.js:

    jQuery( function ( $ )
    {
    	$( '.rwmb-input' ).sortable();
    } );

    Hope that helps.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Sort fields’ is closed to new replies.