Skip to content

Instantly share code, notes, and snippets.

@tanftw
Last active October 30, 2015 23:42
Show Gist options
  • Save tanftw/0249dbc4db40f7db357b to your computer and use it in GitHub Desktop.
Save tanftw/0249dbc4db40f7db357b to your computer and use it in GitHub Desktop.
Conditional Logic Basic Syntax
<?php
add_filter( 'rwmb_meta_boxes', function( $meta_boxes )
{
$meta_boxes[] = array(
'id' => 'brand_product',
'title' => 'Brands and Products',
'post_types' => array( 'post', 'page' ),
'context' => 'normal',
'priority' => 'high',
// Conditional Logic can be applied to Meta Box
// In this example: Show this Meta Box by default. Hide it when post format is aside
'hidden' => array( 'post_format', 'aside' ),
'fields' => array(
array(
'id' => 'brand',
'name' => 'Brand',
'desc' => 'Pick Your Favourite Brand',
'type' => 'select',
'options' => array(
'Apple' => 'Apple',
'Google' => 'Google',
'Microsoft' => 'Microsoft'
)
),
array(
'id' => 'apple_products',
'name' => 'Which Apple product that you love?',
'type' => 'radio',
'options' => array(
'iPhone' => 'iPhone',
'iPad' => 'iPad',
'Macbook' => 'Macbook',
'iWatch' => 'iWatch'
),
// Conditional Logic can applied to fields
// In this example: Show this field by default,
// hide it when user selected different value than 'Apple' on brand select field
'hidden' => array( 'brand', '!=', 'Apple' )
)
)
);
return $meta_boxes;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment