Can a default WP post table field be added to a metabox tab, ie. post_author?

Support Meta Box AIO Can a default WP post table field be added to a metabox tab, ie. post_author?Resolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #17509
    Darrin BirdDarrin Bird
    Participant

    Hi - Im trying to find out if its possible to add a wordpress field like post_author to a metabox tab section in the admin edit interface.

    I have tried:

    'fields'    = [ [ 'name' = 'Owner ID',
                        'id'   = 'post_author',
                        'type' = 'number',
                        'tab'  = 'details', ]]
    #17542
    Anh TranAnh Tran
    Keymaster

    Hi,

    This is not possible by default. But you can follow this tutorial to do that.

    #17579
    Darrin BirdDarrin Bird
    Participant

    Thanks Anh,

    Can you elaborate a little on the tutorial?

    How is the id 'content' linked to the post_content:

    'id' => 'content',

    to link to it post_author I should add:
    'id' => 'author',

    #17581
    Darrin BirdDarrin Bird
    Participant

    Thought it might help if I showed you what I'm trying, which doesn't seem to be working.

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {

    global $wpdb;

    // Get the current post content and set as the default value for the wysiwyg field.
    $default_post_author = '';
    $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
    if( !$post_id ) {
    $post_id = filter_input( INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT );
    }
    if( $post_id ) {
    $default_post_author = get_post_field( 'post_author', $post_id );
    }

    $meta_boxes[] = [ 'title' => 'Enrolment Details',
    'post_types' => 'enrolment',
    'storage_type' => 'custom_table', // Important
    'table' => "{$wpdb->prefix}enrolment_metadata", // Your custom table name
    'tabs' => [ 'details' => 'Enrolment Details',
    'surveys' => 'Surveys' ],

    'tab_style' => 'box',
    'fields' => [ [ 'name' => 'User ID',
    'id' => 'author', // This is the must!
    'type' => 'number',
    'std' => $default_post_author,
    'tab' => 'details' ], ]
    ];
    return $meta_boxes;
    });

    // Do not save to post meta.
    add_filter( 'rwmb_author_value', '__return_empty_string' );

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