Custom Fields
Re-Envisioned
Support Meta Box AIO Can a default WP post table field be added to a metabox tab, ie. post_author?

  • Creator
    Topic
  • #17509
    Resolved Ms Georgina Holmes
    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', ]]
Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #17542
    Anh Tran
    Keymaster

    Hi,

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

    #17579
    Ms Georgina Holmes
    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
    Ms Georgina Holmes
    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 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.