Group data in custom table not printed via shortcode
- This topic has 4 replies, 2 voices, and was last updated 5 years, 5 months ago by
Neal.
-
AuthorPosts
-
December 3, 2019 at 4:19 AM #17304
Neal
ParticipantHi Anh,
Yesterday I purchased a lifetime license and I am already having fun with the Meta Box plugin.
One thing that I am trying to figure out is to show the group data that is stored in a custom table via a shortcode. I am following your tutorial on how to create the shortcode and have this:add_shortcode( 'dr_pricing', function() { $group = rwmb_meta( 'pricing_group' ); if ( empty( $group ) ) { return ''; } $output = ''; // Sub-field Class. $groupclass = $group['group_class'] ?? ''; $output .= '<h3 class="my-title">' . $groupclass . '</h3>'; // Sub-field Number of Classes. $groupnumber = $group['number_of_classes'] ?? ''; $output .= '<h3 class="my-title">' . $groupnumber . '</h3>'; // Sub-field Price. $groupprice = $group['group_price'] ?? ''; $output .= '<h3 class="my-title">' . $groupprice . '</h3>'; // Sub-field No Classes. $noclass = $group['no_class'] ?? ''; $output .= '<h3 class="my-title">' . $noclass . '</h3>'; return $output; } );
When I look in the custom database table I can see that the group data is stored as expected but it is not printed with shortcode [dr_pricing].
Do I need to alter the shortcode function to point to the custom database table? I could not find that piece of information in the tutorial or forum.Thanks so much!
December 3, 2019 at 3:27 PM #17318Anh Tran
KeymasterHi Neal,
When getting the data from a custom table, you need to pass parameters to the
rwmb_meta
function, like this:$value = rwmb_meta( $field_id, ['storage_type' => 'custom_table', 'table' => $table_name] );
Please try that.
December 5, 2019 at 4:47 AM #17363Neal
ParticipantThanks Anh!
It is still not pulling the data in. This is what I have:
add_shortcode( 'dr_pricing', function() { $group = rwmb_meta( 'pricing_group', ['storage_type' => 'custom_table', 'table' => 'dr_workshops_page_settings'] ); if ( empty( $group ) ) { return ''; } $output = ''; // Sub-field Class. $groupclass = $group['group_class'] ?? ''; $output .= '<h3 class="my-title">' . $groupclass . '</h3>'; // Sub-field Number of Classes. $groupnumber = $group['number_of_classes'] ?? ''; $output .= '<h3 class="my-title">' . $groupnumber . '</h3>'; // Sub-field Price. $groupprice = $group['group_price'] ?? ''; $output .= '<h3 class="my-title">' . $groupprice . '</h3>'; // Sub-field No Classes. $noclass = $group['no_class'] ?? ''; $output .= '<h3 class="my-title">' . $noclass . '</h3>'; return $output; } );
When I check the source code of the page I can see the HTML code: <h3 class="my-title"> </h3> but no data is pulled in, although the data is present in the database.
December 6, 2019 at 3:35 PM #17415Anh Tran
KeymasterHi Neal,
Please see this video: https://www.loom.com/share/600b5473ebc343fdaaf440717af7088a
I made a demo based on your code and it works.
December 7, 2019 at 1:20 AM #17441Neal
ParticipantHi Anh,
Thanks so much for creating the video! I see what you did there and with the small adjustments that you mentioned in the video to call the cloned fields it works like a charm!
Thanks so much for your support. This already makes it so much worth to have invested in the pro version of Meta Box.
You are the best!
-
AuthorPosts
- You must be logged in to reply to this topic.