Forum Replies Created
-
AuthorPosts
-
Tan Nguyen
ParticipantHi Cararina,
Sorry for long response, we're still in progress to improving Conditional Logic. As this plugin uses Javascript to handle visibility of object and have to check many field conditional to generate results so it's hard to implements now. In your case, we'll have two ways to make it works natively:
1. Save it as
cel_product_apple,cel_product_androidorcel_product_windowsphonein DB then usefone_idto check what's field to output.2. Save
cel_product_apple,cel_product_androidorcel_product_windowsphonein DB, then create another hidden field namedcel_product, when post is saved, we also save the visible field tocel_productas an serialized array, then useunserializefunction to show up.Example (2),
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', 'fields' => array( array( 'id' => 'fone_id', 'name' => 'Brand', 'desc' => 'Pick Your Favourite Brand', 'type' => 'select', 'options' => array( 'apple' => 'Apple', 'android' => 'Android', 'windowsphone' => 'WindowsPhone' ) ), array( 'id' => 'cel_product', 'type' => 'hidden', ), array( 'id' => 'cel_product_apple', 'name' => 'Select your apple product?', 'type' => 'checkbox_list', 'options' => array('iPhone', 'iPad', 'iPod'), 'visible' => array( 'fone_id', 'apple' ) ), array( 'id' => 'cel_product_android', 'name' => 'Select your android product?', 'type' => 'checkbox_list', 'options' => array('Galaxy', 'ZenPhone', 'Tablet'), 'visible' => array( 'fone_id', 'android' ) ), array( 'id' => 'cel_product_windowsphone', 'name' => 'Select your apple product?', 'type' => 'checkbox_list', 'options' => array( 'Nokia', 'Galaxy' ), 'visible' => array( 'fone_id', 'windowsphone' ) ) ) ); return $meta_boxes; } ); add_action('rwmb_before_save_post', function($post_id) { // Get person ID to save from "Select a Customer" field $metabox_to_save = $_POST['fone_id']; // Save related field to phone field if ( ! empty( $_POST["cel_product_{$metabox_to_save}"] ) ) $_POST['cel_product'] = serialize( $_POST["cel_product_{$metabox_to_save}"] ); // Clear all hidden meta boxes foreach ( array('apple', 'android', 'windowsphone') as $field ) { if ( $field !== $metabox_to_save ) unset( $_POST["cel_product_{$field}"] ); } } );To retrieve values in front end, just use:
$cel_products = unserialize( rwmb_meta('cel_product') );Best regards
Tan Nguyen
Tan Nguyen
ParticipantThanks Sam very much for reporting this bug, we're working and release the patch for Group shortly ๐
September 11, 2015 at 1:45 PM in reply to: Conditional Logic Between Checklist Group and Checkbox #1420Tan Nguyen
ParticipantDear Justin,
I've checked with and it works, can you please tell me what's version you're using and provide your code to register meta boxes and define conditional logic?
Here's my snippet for example:
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', 'fields' => array( array( 'id' => 'show_checkboxlist', 'name' => 'Show Checkbox List', 'desc' => 'Show Checkbox List when this checkbox is checked', 'type' => 'checkbox' ), array( 'id' => 'brand', 'name' => 'Brand', 'desc' => 'Pick Your Favourite Brand', 'type' => 'checkbox_list', 'options' => array( 'Apple' => 'Apple', 'Google' => 'Google', 'Microsoft' => 'Microsoft' ), 'visible' => array('show_checkboxlist', true) ) ) ); return $meta_boxes; } );Best regards
Tan
September 11, 2015 at 1:34 PM in reply to: Conditional Logic Between Checklist Group and Checkbox #1419Tan Nguyen
ParticipantHi Justin, sorry for long silence, I'm checking this issue and give you an answer shortly ๐
Tan Nguyen
ParticipantHi Jon,
Sorry for late reply, I just back again and wonder to see that you can fix your code easily, brilliant.
I can see you set
'column' => 4for some 'hidden' fields, it's not necessary as these fields are hidden and some repeated code can be rewrite to cleaner ๐All foreach like so:
... foreach ( $_POST as $key => $value ) { if ( strpos( $key, 'p52_quote_phone_' ) ) unset( $_POST[$key] ); } ...Can be combine and rewrite to 1 foreach like so:
foreach ( $_POST as $key => $value ) { if ( strpos( $key, 'p52_quote_phone_' ) || strpos( $key, 'p52_quote_company_' ) || strpos( $key, 'p52_quote_delivery_address' ) ... ) // Replace ... with all fake fields you've set unset( $_POST[$key] ); }For cloned group, I firstly designed for 1 product only and if we switch to cloned groups, it's time consuming because it's related to populate custom data and out of our scope, we're sorry about that.
Best Regards
Tan
Tan Nguyen
ParticipantYeah, glad to meet you, an Australian who like Breaking Bad show like me ๐
Tan Nguyen
ParticipantHi Jon, it's really weird if it return empty value even though customer phone has set. Can you please give me credentials to your website to check? Include FTP and WP-Admin? Can you send me via my email to check it faster? My email is: [email protected]
Tan Nguyen
ParticipantCan you please check the database (wp_postmeta) to see the records exists here?
Basically, it grabs value from postmeta table and bind to meta box as I defined in this line:
'std' => get_post_meta( $customer->ID, 'p52_quote_phone', true ),So if the customer has phone entered, this should be bound to field via
stdkey.I'm very happy to see you're going to the last steps ๐ This is a great challenge ๐
Tan Nguyen
ParticipantOh, sorry, remove the square bracket and keep it $meta_box because I have assign $meta_boxes[] = $meta_box later ๐
Tan Nguyen
ParticipantI means only remove square bracket only with $meta_box below, like my example in the previous page.
// start customerTan Nguyen
ParticipantHi Jon, I found another problem on your code:
// start customer $meta_boxes[] = array(You can remove [], it just $meta_box.
On step value, can you please change to full value contains zero sign, 0.01 instead of 'step' => .01?
If you still get error, try to comment out some other Meta Box (I though is Groups), to check what meta boxes generate error ๐
Tan Nguyen
ParticipantDid you have anoter Group field or other Meta Boxes?
Tan Nguyen
ParticipantHi carassius
To explain it more clearly, I've basically created two fields, as defined in this array:
'fields' => array( array( 'name' => 'Name', 'id' => $prefix . 'name', 'type' => 'post', 'post_type' => 'customer', 'placeholder' => 'Select a Customer' ), // Real field array( 'name' => 'Phone', 'id' => $prefix . 'phone', 'type' => 'hidden' ) )There're two fields called
p52_quote_namewhich type is ispostandp52_quote_phonewhich ishiddenfield, this field will hold the real value. ($prefix = 'p52_quote_' as you defined)I've also created a bunch of input text fields, each field has ID:
p52_quote_phone_$customer_idwhich customer ID is the post ID, and the default value is the customer phone, as this snippet:foreach ( $customers as $customer ) { // Show this phone field if match name. $meta_box['fields'][] = array( 'name' => 'Phone', 'id' => $prefix . 'phone_' . $customer->ID, 'type' => 'text', 'std' => get_post_meta( $customer->ID, 'p52_quote_phone', true ), 'visible' => array( $prefix . 'name', $customer->ID ) ); }You can see
'visible' => array( $prefix . 'name', $customer->ID )That means, visible this field, when the select customer name is equal to customer ID, that means if we have two persons with phones, for example called:
ID 1: Jim : 0123456789 ID 2: Kane: 0139401451So, if Jim, ID 1 (
p52_quote_name) is selected, the field,p52_quote_phone_1will visible with default value defined instdis: 0123456789This snippet wich you've asked is to remove all faked text fields defined above, and store visible field (
p52_quote_phone_1) top52_quote_phonefield ๐// Save data to phone field add_action('rwmb_before_save_post', function($post_id) { // Get person ID to save from "Select a Customer" field $person_to_save = intval( $_POST['p52_quote_name'] ); // Save related field to phone field $_POST['p52_quote_phone'] = $_POST['p52_quote_phone_' . $person_to_save]; // Unset all hidden fields foreach ( $_POST as $key => $value ) { if ( strpos( $key, 'p52_quote_phone_' ) ) unset( $_POST[$key] ); } } );If you still have problem, can you give me your site information to debug?
Tan Nguyen
ParticipantHi Jan,
We're working MB Builder to release new version with contains improvement for roles & permissions. You'll get a update notice on this weekend.
Thanks for using and reporting.
Tan Nguyen
ParticipantHi Maurice,
Yes, we do have shortcode to display on singular pages ๐
[rwmb_meta meta_key="$meta_key"][/rwmb_meta]Where
$meta_keyis the field ID.To display post meta on other pages or specify post id meta, you can add post_id attribute, like so:
[rwmb_meta post_id="$post_id" meta_key="$meta_key"][/rwmb_meta]Best regards
Tan Nguyen.
-
AuthorPosts