Support

Account

Home Forums Front-end Issues Schedule Post with Frontend Form? Reply To: Schedule Post with Frontend Form?

  • The first thing you need to do is move acf_form_head(); to before get_header(); http://www.advancedcustomfields.com/resources/acf_form/

    Then in functions.php

     
    add_filter('acf/pre_save_post' , 'shareable_pre_save_post', 10, 1 );
    function shareable_pre_save_post($post_id) {
      // check if this is to be a new post
      if ($post_id != 'new_shareable') {
        return $post_id;
      }
      // The date picker field
      // change field_563657f49b4d9 to the field key of your date field
      $postdate = date('Y-m-d H:i:s', strtotime($_POST['acf']['field_563657f49b4d9']));
      
      // Create a new post
      $post = array(
        'post_type' => 'shareable',
        'post_title' => $_POST['acf']['_post_title'],
        'post_status'  => 'future',
        'post_date'  => $postdate
      );  
      
      // insert the post
      $post_id = wp_insert_post( $post ); 
      
      // return the new ID
      return $post_id;
    }
    

    Then in your template where you want to show the form

    
    $args = array(
      'post_id'    => 'new_shareable',
      'post_title' => true,
      'field_groups' => array(3498), // change to ID of the field group to show
      'submit_value'    => 'Create post'  
    );  
    acf_form($args);