Support

Account

Home Forums General Issues Field last update date stamp? Reply To: Field last update date stamp?

  • For those interested, below is the final code that worked. The above $headers code doesn’t work because of the double quotes, and even then, it doesn’t work. I’m guessing that the codex hasn’t been updated in a long time for that. But I managed to find a solution that works.

    To recap, the use case here is where I have a custom post type setup just for having an online design approval system. I have it set to not be archived and scanned by search engines. Soon each page will only be visible to specific users who must log in. Using acf_form() I have it set to update two custom fields. Since the validation aspect of ACF doesn’t work for forms (because you’d have to fill them in when you create the page in the first place) I have set up a sort of “faux” validation. There is a hidden div that will only display if, and only if both of those fields in the form have a value. When it does, the div containing the form is hidden and the previously hidden one is unhidden. The email notification is then only triggered if, and only if both of the fields have a value.

    If anyone is interested in a full demo of how it works live and would like the full code, just let me know.

    
    // Updates FYI last update timestamp when custom field is updated and notify admin
    function my_acf_save_post( $post_id ) {
      // bail out early if we don't need to update the date
      if( is_admin() || $post_id == 'new' ) {
         return;
       }
       global $wpdb;
    
       $datetime = date("F j, Y g:i a");
       $query = "UPDATE $wpdb->posts
    	     SET
                  post_modified = '$datetime'
                 WHERE
                  ID = '$post_id'";
        $wpdb->query( $query );
    	
    	$print_approved = get_field('approved_by');
    	$approved_email = get_field('approval_email');
    	$to = '[email protected]';
    	$subject = get_the_title($post_id) .' Design Approved';
    	$message = 'The design was approved by '. $print_approved .' ('.$approved_email.') to be sent to print.';
    	
    add_filter('wp_mail_from', 'new_mail_from');
    add_filter('wp_mail_from_name', 'new_mail_from_name');
    
    function new_mail_from($old) {
        return '[email protected]';
    }
    function new_mail_from_name($old) {
        return 'Spiderfly Studios';
    }
    
    if ( $approved_email && $print_approved ) {
    	wp_mail( $to, $subject, $message );
    }
    }
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);