Advertisement
longnguyenwp

MB Conditional Logic: not working with subfields in classic editor mode

Jul 18th, 2022
1,406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.42 KB | None | 0 0
  1. add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
  2.  
  3. function your_prefix_function_name( $meta_boxes ) {
  4.     $prefix = 'section_';
  5.  
  6.     $meta_boxes[] = [
  7.         'title'      => __( 'Sections', 'your-text-domain' ),
  8.         'id'         => 'sections',
  9.         'post_types' => ['page'],
  10.         'fields'     => [
  11.             [
  12.                 'id'         => $prefix . 'group',
  13.                 'type'       => 'group',
  14.                 'clone'      => true,
  15.                 'sort_clone' => true,
  16.                 'add_button' => __( '+ Add Section', 'your-text-domain' ),
  17.                 'fields'     => [
  18.                     [
  19.                         'name'        => __( 'Section Type', 'your-text-domain' ),
  20.                         'id'          => $prefix . 'type',
  21.                         'type'        => 'select',
  22.                         'options'     => [
  23.                             'hero'    => __( 'Hero', 'your-text-domain' ),
  24.                             'cta'     => __( 'Call To Action', 'your-text-domain' ),
  25.                             'faq'     => __( 'FAQ', 'your-text-domain' ),
  26.                             'wysiwyg' => __( 'WYSIWYG', 'your-text-domain' ),
  27.                         ],
  28.                         'placeholder' => __( 'Select section type ', 'your-text-domain' ),
  29.                     ],
  30.                     [
  31.                         'name'    => __( 'Title', 'your-text-domain' ),
  32.                         'id'      => $prefix . 'title',
  33.                         'type'    => 'text',
  34.                         'visible' => [
  35.                             'when'     => [['type', 'contains', 'hero'], ['type', 'contains', 'faq']],
  36.                             'relation' => 'or',
  37.                         ],
  38.                     ],
  39.                     [
  40.                         'name'    => __( 'WYSIWYG', 'your-text-domain' ),
  41.                         'id'      => $prefix . 'wysiwyg',
  42.                         'type'    => 'wysiwyg',
  43.                         'visible' => [
  44.                             'when'     => [['type', 'contains', 'wysiwyg']],
  45.                             'relation' => 'or',
  46.                         ],
  47.                     ],
  48.                     [
  49.                         'id'         => $prefix . 'faq_items',
  50.                         'type'       => 'group',
  51.                         'clone'      => true,
  52.                         'sort_clone' => true,
  53.                         'add_button' => __( '+ Add FAQ', 'your-text-domain' ),
  54.                         'fields'     => [
  55.                             [
  56.                                 'name' => __( 'Question', 'your-text-domain' ),
  57.                                 'id'   => $prefix . 'question',
  58.                                 'type' => 'text',
  59.                             ],
  60.                             [
  61.                                 'name' => __( 'Answer', 'your-text-domain' ),
  62.                                 'id'   => $prefix . 'answer',
  63.                                 'type' => 'textarea',
  64.                             ],
  65.                         ],
  66.                         'visible'    => [
  67.                             'when'     => [['type', 'contains', 'faq']],
  68.                             'relation' => 'or',
  69.                         ],
  70.                     ],
  71.                 ],
  72.             ],
  73.         ],
  74.     ];
  75.  
  76.     return $meta_boxes;
  77. }
  78.  
  79. add_filter('use_block_editor_for_post_type', '__return_false', 10);
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement