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 Date Field with Today’s Date

This short CRED Code allows you to get the TODAY’s Date in seconds from Timestamp begin and update a Date Field (Types) with this value. Since Views can currently not handle post_date in Parametric Searches this can be useful to find posts by Publish Date (let’s say you updated the CF with TODAY date on post creation)

/** 
  *Update news post date to a CF since Views cant handle Post Date in param search
  */
        
    function update_post_date_save_data_action($post_id, $form_data){
            
        // Change your CRED Form "ID" accordingly below
        if ($form_data['id']==ID){
                
            // get current date, returns full Timestamp
            $post_date = date("U");
                
            //update the CF with current post date

            update_post_meta( $post_id, 'wpcf-date_field_slug', $post_date );       
        }
    }
add_action('cred_save_data', 'update_post_date_save_data_action',10,2);

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

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

Post navigation

Previous post: Assign different Layout depending on Post Status
Next post: Remove the Admin Bar depending on User Role
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