Home Forums General Issues Dynamically fill a custom field with publish date


Dynamically fill a custom field with publish date

    • jaryup

    • October 1, 2020 at 12:35 am


    I created a custom field and I want him to dynamically fill the publish post date when I publish a post.

    Example :
    If I publish a post today, I want when the action of publishing is done to find 30/09/2020 in my custom field
    If I schedule my post for tomorrow then I want to find tomorrow 01/10/2020 in my custom field.
    Same idea if I publish my article at an earlier date.

    I already tried this :

    add_action('acf/save_post', 'my_acf_save_post');
    function my_acf_save_post( $post_id ) { 
        $value = get_the_date();
        update_field('name_of_my_custom_field', $value, $post_id);

    But I always get today’s date and not the real published date.

    One other thing, I don’t want my custom field to update when I will update my post in the future. So I thought about a condition like : IF my custom field is not empty THEN i do nothing but I am not able to do it.

    Any ideas ?

    Thanks by advance and sorry for my poor english.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.