Forum Replies Created
-
AuthorPosts
-
December 19, 2019 at 12:06 PM in reply to: ✅Can a default WP post table field be added to a metabox tab, ie. post_author? #17581
Darrin Bird
ParticipantThought 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' );December 19, 2019 at 10:48 AM in reply to: ✅Can a default WP post table field be added to a metabox tab, ie. post_author? #17579Darrin Bird
ParticipantThanks 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', -
AuthorPosts