Search code examples
phpwpallimport

PHP - How set date and time stamp in a Custom Field during import


I’d like to set the current date and time to a Custom Field 'Latest update' when running an import via cron on a regular basis, so I can see when the last update successfully ran. Note: I realize WP All Import has logs but I want to show the custom 'Latest update' field in the product admin listing and check if the pricing was updated whilst doing other product updates dependent on the latest import.

I tried many PHP functions but none work so far. Could you let me know what I should do instead? Some variations I tried and the error I get:

[print date(“d-m-Y H:i”)] : ERROR: Call to undefined function “print date”
[echo date(“d-m-Y H:i”)] : ERROR: Call to undefined function “echo date”
[print date (“d-m-Y H:i”)] : ERROR: Unexpected token OPEN, statement was expected.
[print date = date(“d-m-Y H:i”)] : ERROR: Unexpected token OPEN, statement was expected.
[date = date(“d-m-Y H:i”)] : ERROR: Unexpected token OPEN, statement was expected.
[date = date(”d-m-Y H:i”)] : ERROR: Unexpected symbol ‘

– When using shortcodes/PHP functions, use double quotes “, not single quotes ‘

I read that I should use ” instead of single quote ‘ (as is in one of the errors) so that one is clear. But what else am I doing wrong?

Does anyone have a solution?

I don't mind whether the Custom Field 'Latest update' is a text field or a data field (I tried both with all PHP function options above) let me know if relevant for a solution offered how I should format the custom field.

I'd really appreciate your help!


Solution

  • The answer I got from WPAllImport:

    [date("d-m-Y H:i")]
    

    It works. Thought I'd share it in case it helps others.