Created
April 3, 2017 21:16
-
-
Save anonymous/0c6aad33f510e491dd4604cd1beb74fa to your computer and use it in GitHub Desktop.
MB Conditional Logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) | |
{ | |
$meta_boxes[] = array( | |
'id' => 'geolocation', | |
'title' => 'GeoLocation', | |
'context' => 'normal', | |
'priority' => 'high', | |
// Tell WP this Meta Box is GeoLocation | |
'geo' => true, | |
// Or you can set advanced settings for Geo, like this example: | |
// Restrict results to Australia only. | |
// Uncomment to use it. | |
// 'geo' => array( | |
// 'componentRestrictions' => array( | |
// 'country' => 'au' | |
// ) | |
// ), | |
'fields' => array( | |
array( | |
'id' => "address", | |
'name' => __( 'Address', 'webx' ), | |
'type' => 'text', | |
'std' => __( 'Innsbruck, Austria', 'webx' ), | |
'hidden' => array( "post_format", 'aside'), | |
), | |
array( | |
'id' => "map", | |
'name' => __( 'Location', 'webx' ), | |
'type' => 'map', | |
'std' => '47.2643292,11.3963643', | |
'address_field' => "address", | |
'api_key' => 'super-fancy-google-maps-key', | |
'hidden' => array( "post_format", 'aside'), | |
), | |
// Auto populate `postal_code` to this field | |
array( | |
'type' => 'number', | |
'name' => 'Postcode', | |
'id' => 'postal_code' | |
), | |
// Auto populate also works with Select field. In case you want to limit your result like this example. | |
// Auto populate short name of `administrative_area_level_1`. For example: QLD | |
array( | |
'type' => 'select', | |
'name' => 'State', | |
'placeholder' => 'Select a State', | |
'options' => array( | |
'ACT' => 'ACT', | |
'QLD' => 'QLD', | |
'NSW' => 'NSW', | |
'NT' => 'NT', | |
'SA' => 'SA', | |
'TAS' => 'TAS', | |
'VIC' => 'VIC', | |
'WA' => 'WA' | |
), | |
'id' => 'administrative_area_level_1_short' | |
), | |
// You can set different ID but still can auto populate `route` to this field. | |
array( | |
'type' => 'text', | |
'name' => 'Route', | |
'id' => 'dummy_field', | |
'binding' => 'route' | |
), | |
// We have custom `geometry` address component. Which is `lat + ',' + lng` | |
array( | |
'type' => 'text', | |
'name' => 'Geometry', | |
'id' => 'geometry' | |
), | |
// But you can always use Binding Template to bind data like so | |
array( | |
'type' => 'text', | |
'name' => 'Geometry with custom template', | |
'id' => 'geometry2', | |
'binding' => 'lat + "," + lng' // lat,lng | |
), | |
// Here is the advanced usage of Binding Template. | |
// Put any address component + anything you want | |
array( | |
'type' => 'text', | |
'name' => 'State + Country', | |
'id' => 'state_country', | |
// Example Output: QLD AU | |
'binding' => 'short:administrative_area_level_1 + " " + country' | |
), | |
) | |
); | |
return $meta_boxes; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment