Forum Replies Created
-
AuthorPosts
-
April 30, 2020 at 12:14 AM in reply to: ✅How to create a unique identifier for each group when using clonable/sortable #19381
realj42
ParticipantNo worries - turns out I was invoking this code in my plugin startup code, straight after declaring the settings metabox, which is why it wasn't working. Instead, using rwmb_meta() in a shortcode function it works fine for me.
I could point out that getting option values during startup is pretty standard so I will allways use get_option() in that situation in future.
April 29, 2020 at 6:18 PM in reply to: ✅How to create a unique identifier for each group when using clonable/sortable #19371realj42
ParticipantHi Long
Thanks again but just FYI when I am using the code above, when I try to retrieve the value with
$video_options_list = rwmb_meta('settings_test_video_list', ['object_type' => 'setting'], 'settings_test' );
then nothing is returned. Is that the correct way to get the field? I also cannot get the single field 'settings_test_single_id' using rwmb_meta().
No worries though because 'get_option()' works fine -
$settings_test = get_option('settings_test'); $single = $settings_test['settings_test_single_id']; $video_options_list = $settings_test['settings_test_video_list'];All expected vallues/arrays returned fine
April 28, 2020 at 7:53 PM in reply to: ✅How to create a unique identifier for each group when using clonable/sortable #19341realj42
ParticipantHi Long
Brilliant, thanks for explaining that - I should have realised that everything is at the gropup level for a group of fields!
April 27, 2020 at 2:18 AM in reply to: ✅How to create a unique identifier for each group when using clonable/sortable #19296realj42
ParticipantHi Long
Thanks for your reply. The problem is I am trying to create a pseudo index field I can use in the select vaule on the Page meta. So on the settings page with the list of videos I have added a 'video id' field which I need to automatically increment to create a unique Id for each row in the group. For a single, non cloned, field I can use the Rwmb_{field_id}_value filter to set the index value if it is empty or leave alone if it is already set. But for a cloneable group field that filter does not work.
Here is my testing settings page definition with test code filters to test the 'value' filter.
// Register meta boxes and fields for settings page add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) { $prefix = "settings_test_"; $meta_boxes[] = array( 'id' => $prefix .'general', 'title' => 'General', 'settings_pages' => 'settings_test', 'tab' => 'general', 'fields' => array( array( 'type' => 'custom_html', 'std' => 'General theme settings will be added here', ), array( 'name' => 'Single Id', 'id' => $prefix . 'single_id', 'type' => 'number', 'std' => 0, ), ), ); $meta_boxes[] = array( 'id' => $prefix . 'videos', 'title' => 'Highlight Video Options', 'settings_pages' => 'settings_test', 'tab' => 'highlights', 'fields' => array( array( 'type' => 'custom_html', 'std' => 'Here is the list of highlight videos. Add videos here to be included in the highlight video list.', ), array( 'id' => $prefix . 'video_list', // Group field 'name' => "Videos", 'type' => 'group', // Clone whole group? 'clone' => true, // Drag and drop clones to reorder them? 'sort_clone' => true, 'collapsible' => true, 'group_title' => array( 'field' => $prefix .'video_name' ), // ID of the subfield 'save_state' => true, // Sub-fields 'fields' => array( array( 'name' => 'Video Name', 'id' => $prefix . 'video_name', 'description' => 'Name for dropdown list', 'type' => 'text' ), array( 'name' => 'Video URL', 'id' => $prefix . 'video_url', 'type' => 'url' ), array( 'name' => 'Id', 'id' => $prefix . 'video_id', 'type' => 'number', 'std' => 0, ) ), ), ), ); $meta_boxes[] = array( 'id' => 'info', 'title' => 'Theme Info', 'settings_pages' => 'settings_test', 'tab' => 'faq', 'fields' => array( array( 'type' => 'custom_html', 'std' => 'Having questions? Check out our documentation', ), ), ); return $meta_boxes; } ); add_filter('rwmb_settings_test_video_id_value', 'settings_test_autoinc_value', 10, 3 ); function settings_test_autoinc_value($new, $field, $old) { global $shsLog; $shsLog->trace("Entry - New - $new - old - $old"); if (empty($new)) { $new = 4222; }else { $new = 21223; } return $new; } add_filter('rwmb_settings_test_single_id_value', 'settings_test_single_value', 10, 3 ); function settings_test_single_value($new, $field, $old) { global $shsLog; $shsLog->trace("Entry - New - $new - old - $old"); if (empty($new)) { $new = 4222; }else { $new = 21223; } return $new; }In testing the filter 'settings_test_single_value()' is called as expected. However the filter for the cloned id field filter 'settings_test_autoinc_value()' is never called. I have tried creating a custom field type but the ::value() function is never called if the field is cloneable.
Is there anyway round this?
Cheers
HywelMarch 29, 2020 at 5:59 AM in reply to: ✅Version 1.50 removed MB_Admin_Columns_User and MB_Admin_Columns_Post classes #18725realj42
ParticipantBrian - just switch to
class Your_Class extends \MBAC\Post {which works fine. If you need to support upgraded and non upgraded environments this should work with 1.50 and pre 1.50
`if (class_exists('MB_ADMIN_COLUMNS_POST')) { class SHS_MBAC extends MB_ADMIN_COLUMNS_POST { } } elseif (class_exists('\MBAC\Post')) { class SHS_MBAC extends \MBAC\Post { } } class SHS_Member_Link_Columns extends SHS_MBAC { public function columns( $columns ) { `February 19, 2020 at 4:48 PM in reply to: ✅MetaBox user field - how to show current value when query args exclude it #18343realj42
ParticipantThanks Anh Tran, should have realised that!
February 17, 2020 at 11:25 PM in reply to: ✅MetaBox user field - how to show current value when query args exclude it #18325realj42
ParticipantHi that is great,thanks. I assume this code should be placed in an rwmb_before() action callback?
Cheers
Hywel -
AuthorPosts