Forum Replies Created
-
AuthorPosts
-
December 4, 2020 at 5:40 AM in reply to: ✅Bug (maybe) MB Custom Table with Select Advanced field #23409
Trang Nguyen
ParticipantMany thanks, Long
Have a nice weekend!Trang Nguyen
ParticipantIt works!!!!
I sincerely thank you and appreciate your patience, Long.
Have a nice night!Trang Nguyen
ParticipantHi Long, I just double-checked.
It's true that the code runs smoothly with that field structure. Many thanks for recording the video.But the field structure I'm using has some other fields on the same level as group2. I have something likes this:
group1 (cloneable) |__text |__select |__group2 (cloneable) |__language (multiple select)And it leads to error on the line
foreach ( $group1_field_settings['fields'] as $field_settings ) {If I remove the text and select fields, everything works well again.
But if I add any field into the group1, the error will appear.I think it is because the group2 has different data order than the text / select field. But I don't know how to fix it.
Please help!
Thank you in advance.Trang Nguyen
ParticipantHi Long,
It's me again and sorry for disturbing you too much.
I would like to ask could I use this way for a multiple select inside 2 levels of groups?I have fields like this:
group1 (cloneable) |__group2 (cloneable) |__language (multiple select)(language is inside group2, group2 is inside group1)
I used your hint
echo "<pre>"; print_r( $group_settings ); echo "</pre>";and saw that I have to take out 2 'fields' of groups settings.
So I tried this code
$group1 = rwmb_meta( 'group1', ['storage_type' => 'custom_table', 'table' => 'custom'] ); $group1_settings = rwmb_get_field_settings( 'group1' ); foreach ( $group1 as $group1_value ) { $group2 = $group1_value['group2']; foreach ( $group2 as $group2_value ) { $multi_select = $group2_value['language']; foreach ( $multi_select as $select_value ) { foreach ( $group1_settings['fields'] as $group1_field_settings ) { foreach ( $group1_field_settings['fields'] as $field_settings ) { foreach ( $field_settings as $setting_key => $setting_value ) { if ( $setting_key == 'options' ) { echo $setting_value[$select_value]; } } } } } } }Unlucky me, I got error on the line
foreach ( $group1_field_settings['fields'] as $field_settings ) {I'm so sorry, I'm bad at PHP. Please take a look a help me to solve this issue.
Many many thanks!
Trang Nguyen
ParticipantWonderful! It works like a charm.
Many thanks, Long!Trang Nguyen
ParticipantHi Long,
Sorry for opening this topic again.I have other select fields that are in a group field in a custom table. I edited your code to work in a custom table and a group field but I got some error warning and it didn't work
$group = rwmb_meta( 'group', ['storage_type' => 'custom_table', 'table' => 'custom'] ); $multi_select = isset( $group['language'] ) ? $group['language'] : ''; $select_settings = rwmb_get_field_settings( $group['language'] ); foreach ( $multi_select as $select_value ) { foreach ( $select_settings as $setting_key => $setting_value ) { if ( $setting_key == 'options' ) { echo $setting_value[$select_value]; } } }I think I make something wrong on the line
$select_settings = rwmb_get_field_settings( $group['language'] );But I really don't know what wrong. Please help!
Thank you!
November 17, 2020 at 7:21 AM in reply to: ✅Bug (maybe) MB Custom Table with Select Advanced field #22871Trang Nguyen
ParticipantHi!
There is another similar issue with Custom Table and Post field with multiple choices:If a post field saves data to a custom table, it also saves 'i:0;s:0:""' before other items.
I choose 2 posts and this is the data I have in the database
a:3:{i:0;s:0:"";i:1;i:194;i:2;i:197;}Because of this, when I use this code
$post_ids = rwmb_meta( $field_id, ['storage_type' => 'custom_table', 'table' => $table_name] ); foreach ( $post_ids as $post_id ) { echo '<p>', get_the_title( $post_id ), '</p>'; }It shows as I have 3 posts, not 2.
Trang Nguyen
ParticipantMany thanks for your help, Long!
Trang Nguyen
ParticipantWow! Many thanks, Long. You saved my time.
Everything is perfect now.
Thank you again!Trang Nguyen
ParticipantHi Long,
Many thanks for your help!I tried rwmb_the_value() and it worked great. Easy and fast. (Thanks again)
But for the fields with multiple choices, rwmb_the_value() always renders with HTML (which I don't want). So I tried the code rwmb_get_field_settings you gave me above:
$select = rwmb_meta( 'select_id' ); $select_settings = rwmb_get_field_settings( 'select_id' ); foreach ( $select_settings as $key => $value ) { if ( $key == 'options' ) { echo $value[$select]; } }It works well with single choice select fields but seems like it doesn't work with multiple choice select fields.
I used the same code, only changed the field setting to multiple choices and it stopped working, with no "echo" info on the front-end.
If I change the field setting back to single choice, it works well as before.So could you please give me a solution for a field with multiple choices!
Thank you!!
Trang Nguyen
ParticipantHi Long,
Many thanks for your links. I could solve the comma issue in no time 🙂But I couldn't solve the label issue. Honestly, I know nothing about PHP, just copy and paste.
I tried this code but it didn't help:$field = rwmb_get_field_settings( 'mb_day'); foreach ( $field as $a ) { echo $a; }I know I have to put something before the loop but I have no idea what.
Could you please help me to modify it to get the labels!It would be great if we have an example on the rwmb_get_field_settings page.
Thank you!
Trang Nguyen
ParticipantMany thanks for your clear explanation, Long!
Have a nice day!Trang Nguyen
ParticipantI'm glad to hear that. Hope it will come soon.
Please close this topic!
Thanks!Trang Nguyen
ParticipantHi, thank you for your link. I read it but it is for showing all the posts and using a template which not what I need.
I need many views to show separate posts depend on many conditions. In this case, they are location and types of attractions (at least).
I use these views as a part in many pages and posts, not for a page with template layout. So I need shortcode of Views to put them in places I want.
For ex: I have attractions in Madrid, Paris, Rome... With the query above, I can show attractions for each city, not all attractions on one page. And I would like to have a map for each city as well.
Thanks
Trang Nguyen
ParticipantThank you very much, Long! It works 100%!
-
AuthorPosts