title: Gravity Forms & Advanced Custom Fields
body: <p>I've successfully created the dropdown menu to auto populate the appropriate information from an Advanced Custom Field I created called 'date' on site <a href="http://albertson.staging.wpengine.com/seminars/" rel="nofollow">http://albertson.staging.wpengine.com/seminars/</a>. </p>
  
  <p>Followed along with the instructions here:</p>
  
  <p><a href="http://www.gravityhelp.com/documentation/page/Dynamically_Populating_Drop_Down_Fields" rel="nofollow">http://www.gravityhelp.com/documentation/page/Dynamically_Populating_Drop_Down_Fields</a></p>
  
  <p>The only issue I'm having is how to display the date in a "pretty" format. You can see that the date is all numbers (20140129) instead of 01/28/2014</p>
  
  <p>To display the date appropriately in the seminar sections above (border red) I use:</p>
  
  <pre><code>&lt;?php if( get_field('date')): ?&gt;
  
  &lt;?php
  $date = get_field('date');
  // $date = 19881123 (23/11/1988)
  
  // extract Y,M,D
  $y = substr($date, 0, 4);
  $m = substr($date, 4, 2);
  $d = substr($date, 6, 2);
  
  // create UNIX
  $time = strtotime("{$d}-{$m}-{$y}");
  
  // format date (November 11th 1988)
  echo date('M d', $time);
  ?&gt;
  </code></pre>
  
  <p>How do I pass this same information within the Gravity Forms Function I created to get the date to display nicely? Below is my function for Gravity Forms so far.</p>
  
  <pre><code>    add_filter('gform_pre_render_4', 'populate_dates');
  
  function populate_dates($form){
  
      foreach($form['fields'] as &amp;$field){
  
          if($field['type'] != 'select' || strpos($field['cssClass'], 'populate-dates') === false)
              continue;
  
          // you can add additional parameters here to alter the posts that are retreieved
          // more info: http://codex.wordpress.org/Template_Tags/get_posts
          $currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
  
          $events = get_posts(array(
                      'post_type' =&gt; 'seminars',
                      'orderby' =&gt; 'date',
                      'order' =&gt; 'ASC',
                      'meta_query'=&gt; array(
                          array(
                            'key' =&gt; 'date',
                            'compare' =&gt; '&gt;=',
                            'value' =&gt; $currentdate,
                            'type' =&gt; 'DATE',
                          )),
                      'meta_key' =&gt; 'date',
                      ));  
  
          // update 'Select a Post' to whatever you'd like the instructive option to be
          $choices = array(array('text' =&gt; 'Select a Date', 'value' =&gt; ' '));
  
          foreach($events as $post){
              $choices[] = array('text' =&gt; $post-&gt;date, 'value' =&gt; $post-&gt;date);
  
          }
  
          $field['choices'] = $choices;
  
      }
  
      return $form;
  }
  </code></pre>