Skip to navigation Skip to content
OTGS Knowledge Base
  • Login
  • Home
  • Add Code Snippets
  • Add Compatibility Snippet
  • Add Content
  • Add Content – Subscriber
  • Add Developer Resource
  • Add Quick Texts
  • Add Supporter Resource
  • Add Trainings
  • Add Webinars
  • All Courses
  • Contractor courses
  • Courses
  • Log In
  • Log Out
  • My Courses
  • New Request
  • Newly added resources
  • Privacy Policy and GDPR Compliance
  • Register
  • Reset Password
  • Set Password
  • Trainings

Update post title/name with a Date from a Types Date CF

Update post title/name with a Date taken from a types Date CF (and obviously you won’t 2664748859 as title but 11-06-2014 or similar) with CRED hook. Remember that Toolset uses Timestamp but you want a “normal” date as Post Title.

function ttd_save_data_action($post_id, $form_data){
            // Change your CRED Form "ID" accordingly below
            if ($form_data['id']==ID){
               
                //Declare the content of your variables, change "your_custom_field_slug" accordingly
                $custom_value = get_post_meta( $post_id, 'wpcf-your_custom_field_slug', true );//get posts' Date field value (timestamp)
                $custom_title = gmdate("m-d-Y", $custom_value);//convert timestamp to m-d-y for output
                //collect data and define new title
                $my_post = array(
                    'ID'               => $post_id,
                    'post_title'   => $custom_title,
                    'post_name' => $custom_title,
                   
                );
               
                // Update the post into the database
                wp_update_post( $my_post );
               
            }
        }
    add_action('cred_save_data', 'ttd_save_data_action',10,2);

Let us know if this snippet is not working for you:

This snippet doesn’t work
Tags: database, front-end admin, get_post_meta, update_post_meta

Post navigation

Previous post: Change DatePicker in Views
Next post: Copy value of child custom field to another, from Parent Post
0 0 votes
Article Rating
Subscribe
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
OnTheGoSystems - One team, one goal
0
0
Would love your thoughts, please comment.x
()
x
| Reply

Report Post

« »

 

Your Name:

Your Email:

Please tell us why do you think this post is inappropriate and shouldn't be there:


Cancel Report