Forum Replies Created
-
AuthorPosts
-
Anh Tran
KeymasterHi bravebits,
Does the answer in the topic https://support.metabox.io/topic/how-to-make-conditional-logic-for-image-upload/ solve your problem? My developer tested with similar code and said it was working.
Regarding your code above, what is your
$prefix? Is itwr?Anh Tran
KeymasterI think the best way to do that is via CSS. You can install a plugin like Add admin CSS. The CSS to make each label display in ins own line is quite simple:
.rwmb-radio-wrapper .rwmb-input > label { display: block; }If you don't want to use a plugin, you can enqueue a CSS file on Add new/Edit page with the same snippet above.
This way you also can add more margin to label for a better look.
But if you have to use PHP to output line break after each label tag, please use
rwmb_radio_htmlfilter, like this:add_filter( 'rwmb_radio_html', function html( $output, $field, $meta ) { $html = array(); $tpl = '<label><input type="radio" class="rwmb-radio" name="%s" value="%s"%s> %s</label>'; foreach ( $field['options'] as $value => $label ) { $html[] = sprintf( $tpl, $field['field_name'], $value, checked( $value, $meta, false ), $label ); } return implode( '<br>', $html ); }, 10, 3 );Anh Tran
KeymasterHi Jon, let me ask my developer if he is interested in working freelance with you on that project and will reply you via email.
Thanks.
Anh Tran
KeymasterHi 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
Anh Tran
KeymasterYeah, glad to meet you, an Australian who like Breaking Bad show like me ๐
Anh Tran
KeymasterHi 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]
Anh Tran
KeymasterCan 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 ๐
Anh Tran
KeymasterOh, sorry, remove the square bracket and keep it $meta_box because I have assign $meta_boxes[] = $meta_box later ๐
Anh Tran
KeymasterI means only remove square bracket only with $meta_box below, like my example in the previous page.
// start customerAnh Tran
KeymasterHi 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 ๐
Anh Tran
KeymasterDid you have anoter Group field or other Meta Boxes?
Anh Tran
KeymasterHi 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?
Anh Tran
KeymasterHi 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.
Anh Tran
KeymasterHi Maurice,
If you want to display meta value in a template file like
single.php, please open that file (notfunctions.php) and insert the following code at the place you want to show the value:echo rwmb_meta( 'FIELD_ID', 'type=FIELD_TYPE' );Don't forget to change
FIELD_IDandFIELD_TYPEto your specific field ID and field type.Anh Tran
KeymasterHi Jan,
You can try the Include Exclude extension. It supports restricting by user role or by user ID and many other conditions.
-
AuthorPosts