Search code examples
phpunix-timestampwpallimport

WP All Import - Convert date to a unix timestamp when importing via a php function


I am using WP All Import plugin for Wordpress and trying to import a date cell but I need it converting from a user friendly date to a unix timestamp.

23/04/2021 13:50

to

1606694400

WP All Import allows me to run a php function when importing into a custom field. I have found we can use the following within php:

strtotime()

I also found the below link to suggest a method of using inline php with the plugin but it's using a price example.

https://www.wpallimport.com/documentation/developers/custom-code/inline-php/

My column containing dates is called Date which the plugin would map data to using:

{date[1]}

Solution

  • Solved this using the below method:

    [strtotime(str_replace("/",".",{date[1]}))]
    

    The above goes into the custom field you want to import the date to and not the PHP Custom Functions tab.

    In my case, I was importing dates for products that are on pre-order. Remember to change the end part:

    {date[1]}
    

    To your column name.

    Image preview is below, however, please note there is NO line break despite it showing it that way.

    Image preview of how to input the code