This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // How to add default values in repeater field in a custom post meta in Crocoblock JetEngine custom post type. | |
| // Note down the repeater field name and all of its sub-fields names | |
| // Create a "Switch" custom meta field after or before the repeater field and apply the condition so it displays only if repeater field is "EMPTY". | |
| // Add the following code to functions.php and replace the field names. | |
| // Now when the switch field is set to TRUE, and post is saved, the repeater field will load default data as defined in the code array. | |
| // The switch field will be hidden when repeater is NOT EMPTY, preventing users to mistakenly override the repeater data. | |
| function load_default_repeaters_data_jetengine($post_id) { | |
| if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; | |
| if (!current_user_can('edit_post', $post_id)) return; |