Skip to content

Instantly share code, notes, and snippets.

View absikandar's full-sized avatar

Abu Bakar Sikandar absikandar

View GitHub Profile
@absikandar
absikandar / functions.php
Last active December 25, 2024 10:15
How to add default values in repeater field in a custom post meta in Crocoblock JetEngine custom post type.
// 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;