Advertisement
longnguyenwp

Blocks select advanced

Nov 23rd, 2023
1,110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. // Register a block for Gutenberg
  2. add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
  3.     $meta_boxes[] = [
  4.         'title' => 'VIEW Post Picker',
  5.         'id'    => 'view-post-picker',
  6.         'type'  => 'block', // Important.
  7.         'icon'  => 'admin-post', // Or you can set a custom SVG if you don't like Dashicons
  8.         'category' => 'text',
  9.         //'context' => 'side', // The block settings will be available on the right sidebar.
  10.         'mode' => 'edit', //The default mode of the block: edit to make it shows the edit fields when loaded, preview (default) to show the rendered HTML when loaded.
  11.         //'render_template' => get_stylesheet_directory() . '/blocks/hero/template.php', // The PHP template that renders the block.
  12.         //'enqueue_style'   => get_stylesheet_directory_uri() . '/blocks/hero/style.css', // CSS file for the block.
  13.  
  14.         // Now register the block fields.
  15.         'fields' => [
  16.             [
  17.                 'id'   => 'vpp_post',
  18.                 'type' => 'post',
  19.                 'name' => 'Post or Page?',
  20.                 'post_type' => ['post','page'],
  21.                 'field_type'  => 'select_advanced',
  22.             ],
  23.             [
  24.                 'id'   => 'vpp_attachment',
  25.                 'type' => 'post',
  26.                 'name' => 'Attachment?',
  27.                 'post_type' => 'attachment',
  28.                 'field_type'  => 'select_advanced',
  29.                 'query_args'  => [
  30.                     'post_status'    => ['publish','inherit'],
  31.                     'posts_per_page' => - 1,
  32.                 ],
  33.             ],
  34.         ],
  35.     ];
  36.     return $meta_boxes;
  37. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement