4

I'm trying to add a column to csv which is exported using a php file.

Down the bottom in post_date is the part where I need to know the correct string to get when the submission/ wordpress post was made. I've currently got a default date request in there but that's just the current time and not the post time. How can you actually get the date the post was made? I would really appreciate the help!

$surveyArray = array(
      'id'                  => $survey_id,
      'title'               => $survey_title,
      'airline'             => $airlineName,
      'meal'                => $mealName,
      'test_great'          => $get_test_great[0],
      'fair_price'          => $get_fair_price[0],
      'friendly_host'       => $get_friendly_host[0],
      'right_temp'          => $get_right_temp[0],
      'looked_good'         => $get_looked_good[0],
      'would_reorder'       => $get_would_reorder[0],
      'comment'             => $get_comment[0],
      'airlane_race_number' => $get_airlane_race_number[0],
      'post_date'       => $postdate = date ("Y-m-d H:i:s"),
  );
  $allAirlinesAndAnswersInArray[] = $surveyArray;

}

BenHoward
  • 43
  • 5
  • check [this](http://stackoverflow.com/questions/12107688/what-to-use-time-function-or-serverrequest-time-which-is-better) – cske Aug 24 '16 at 06:25
  • so you want date of wordpress post when it was created ? – Mittul Chauhan Aug 24 '16 at 06:37
  • can u check [this](https://codex.wordpress.org/Function_Reference/get_the_date) and [this](http://wordpress.stackexchange.com/questions/90321/how-to-get-date-for-each-post) – Mittul Chauhan Aug 24 '16 at 06:38
  • Yes, the date it was posted, not the current time. I've checked those links but not to sure how to integrate them into a string as when I put them in it errors and says it must be a string. Thanks for the fast replies! Really appreciate it! – BenHoward Aug 24 '16 at 06:48

2 Answers2

2

Please use this code for current date and time it's default date time for wordpress

$blogtime = current_time( 'mysql' );

$surveyArray = array(
      'id'                  => $survey_id,
      'title'               => $survey_title,
      'airline'             => $airlineName,
      'meal'                => $mealName,
      'test_great'          => $get_test_great[0],
      'fair_price'          => $get_fair_price[0],
      'friendly_host'       => $get_friendly_host[0],
      'right_temp'          => $get_right_temp[0],
      'looked_good'         => $get_looked_good[0],
      'would_reorder'       => $get_would_reorder[0],
      'comment'             => $get_comment[0],
      'airlane_race_number' => $get_airlane_race_number[0],
      'post_date'       => $blogtime,
  );
  $allAirlinesAndAnswersInArray[] = $surveyArray;
}
kuldip Makadiya
  • 706
  • 4
  • 23
  • Thanks for the quick reply! I tried it and the date goes in but it's the exact same for every post (the current time). 2016-08-24 16:41:35 When I need the post added date/time Why would this be? – BenHoward Aug 24 '16 at 06:43
  • About to leave work in 10 min, will be back tomorrow! Hopefully we can work this out. – BenHoward Aug 24 '16 at 06:55
2

Please, open WP-related topics at Wordpress.Stackexchange.com

p.s. Solution is:

'post_date'       => $postdate = get_the_date( "Y-m-d H:i:s", $survey_id )
T.Todua
  • 53,146
  • 19
  • 236
  • 237