Here is the shortcode I build that will help you to copy the day name value to your new custom field based on the existing date field.
You can add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
Note: don't forget to activated the code snippet once added:
Important: Uncheck the checkbox "WordPress admin" for the code snippet you add.
add_shortcode('add_cfv_for_existing_posts', 'func_add_custom_field_value_for_existing_posts');
function func_add_custom_field_value_for_existing_posts($atts, $content = '') {
extract( shortcode_atts( array(
'post_type' => 'post',
'from_field_slug' => '',
'to_field_slug' => '',
'copy' => false,
), $atts ) );
$get_posts_args = array(
'post_type' => $post_type,
'post_status' => 'publish',
'numberposts' => -1);
$found_posts = get_posts( $get_posts_args );
if($copy) {
foreach($found_posts as $k=>$v):
$old_value = get_post_meta($v->ID,'wpcf-'.$from_field_slug,true);
update_post_meta($v->ID,'wpcf-'.$to_field_slug,$old_value);
endforeach;
}else{
foreach($found_posts as $k=>$v):
$old_value = get_post_meta($v->ID,'wpcf-'.$from_field_slug,true);
$day_name = types_render_field($from_field_slug,array('style'=>'text','format'=>'l','item'=>$v->ID));
update_post_meta($v->ID,'wpcf-'.$to_field_slug,$day_name);
endforeach;
}
}
Before running above code snippet I suggest you take full backup of your ***database and website***:
To run above code snippet, add a new page give the title "toolset test page" and save it. Then add the following shortcode to your page:
[add_cfv_for_existing_posts post_type='agent' from_field_slug='agent-birth-date' to_field_slug='day-name']
'
Where:
- Replace post_type value with your original post_type slug
- Replace from_field_slug value with your original existing date field slug
- Replace to_field_slug value with new custom field slug to which you want to copy the day name
Once you add the above shortcode to "toolset test page" update the page and then try to load the "toolset test page" on frontend only one time.
Later, check few posts in backend to know that the "Day Name" field is populated with correct day name based on your existing date field.