Advertisement
Guest User

Custom table

a guest
Apr 28th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. add_action( 'init', 'my_custom_table1' );
  3. function my_custom_table1() {
  4.     if ( ! class_exists( 'MB_Custom_Table_API' ) ) {
  5.         return;
  6.     }
  7.     MB_Custom_Table_API::create( 'my_custom_table1', array(
  8.     'address' => 'TEXT NOT NULL',
  9.     'phone'   => 'TEXT NOT NULL',
  10.     'email'   => 'VARCHAR(20) NOT NULL',
  11.     'switch' => 'INT'
  12.     ), array( 'email' ) );
  13.  
  14. }
  15.  
  16. add_filter( 'rwmb_meta_boxes', 'register_field_table' );
  17. function register_field_table( $meta_boxes ) {
  18.     $meta_boxes[] = array(
  19.         'title'        => 'Custom table fields',
  20.         'storage_type' => 'custom_table',    // Important
  21.         'table'        => 'my_custom_table1', // Your custom table name
  22.         'post_types'    => 'post',
  23.         'fields'       => array(
  24.             array(
  25.                 'id'   => 'address',
  26.                 'type' => 'text',
  27.                 'name' => 'Address',
  28.             ),
  29.             array(
  30.                 'id'   => 'phone',
  31.                 'type' => 'text',
  32.                 'name' => 'Phone',
  33.             ),
  34.             array(
  35.                 'id'   => 'email',
  36.                 'type' => 'email',
  37.                 'name' => 'Email',
  38.             ),
  39.             array(
  40.                 'id'   => 'switch',
  41.                 'type' => 'switch',
  42.                 'name' => 'Switch',
  43.             ),
  44.         ),
  45.     );
  46.  
  47.     return $meta_boxes;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement