Advertisement
longnguyenwp

Post type select

Apr 19th, 2020
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2. add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
  3.  
  4. function your_prefix_register_meta_boxes( $meta_boxes ) {
  5.     $prefix = '';
  6.  
  7.     $meta_boxes[] = array (
  8.         'title' => esc_html__( 'Untitled Field Group', 'text-domain' ),
  9.         'id' => 'untitled-field-group',
  10.         'post_types' => array(
  11.             0 => 'post',
  12.         ),
  13.         'context' => 'normal',
  14.         'priority' => 'high',
  15.         'fields' => array(
  16.             array (
  17.                 'id' => $prefix . 'select_post_type',
  18.                 'name' => esc_html__( 'Post type', 'text-domain' ),
  19.                 'type' => 'select',
  20.                 'placeholder' => esc_html__( 'Select an Item', 'text-domain' ),
  21.                 'options' => array(
  22.                     'book' => esc_html__( 'book', 'text-domain' ),
  23.                     'author' => esc_html__( 'author', 'text-domain' ),
  24.                     'post' => esc_html__( 'post', 'text-domain' ),
  25.                     'page' => esc_html__( 'page', 'text-domain' ),
  26.                 ),
  27.             ),
  28.             array (
  29.                 'id' => $prefix . 'book',
  30.                 'type' => 'post',
  31.                 'name' => esc_html__( 'Book', 'text-domain' ),
  32.                 'post_type' => array(
  33.                     0 => 'book',
  34.                 ),
  35.                 'field_type' => 'select_advanced',
  36.                 'visible' => array(
  37.                     'when' => array(
  38.                         array (
  39.                             0 => 'select_post_type',
  40.                             1 => '=',
  41.                             2 => 'book',
  42.                         ),
  43.                     ),
  44.                     'relation' => 'and',
  45.                 ),
  46.             ),
  47.             array (
  48.                 'id' => $prefix . 'post',
  49.                 'type' => 'post',
  50.                 'name' => esc_html__( 'Post', 'text-domain' ),
  51.                 'post_type' => array(
  52.                     0 => 'post',
  53.                 ),
  54.                 'field_type' => 'select_advanced',
  55.                 'visible' => array(
  56.                     'when' => array(
  57.                         array (
  58.                             0 => 'select_post_type',
  59.                             1 => '=',
  60.                             2 => 'post',
  61.                         ),
  62.                     ),
  63.                     'relation' => 'and',
  64.                 ),
  65.             ),
  66.         ),
  67.     );
  68.  
  69.     return $meta_boxes;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement