Featured image of post How to Change the Date From Custom Custom Field in Wordpress

How to Change the Date From Custom Custom Field in Wordpress

Learn how to change the date in WordPress by custom field or meta field.

Hi 👋

we will use WordPress get_the_date() Hook.

I will explain both. If you have created meta field for date post_custom_date. OR using ACF created field with name post_custom_date.

Inspiration

When I was developing the site with Divi theme there is a custom post listing module but I don’t want the date of publishing post instead i want my custom date which I have created with ACF.

So I have searched and found this solution Enjoy. 🎉

Put this code in functions.php file.

For custom meta Without Acf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

<?php
    /**
    * @here 10 is Priority and 3 is Number of arguments to be passed
    */
    add_action( 'get_the_date','custom_date_callback', 10 , 3 );
    function custom_date_callback( $the_date, $format, $post ){
        if( get_post_type() === "custom_post_type" && is_singuler("custom_post_type") ){
            $date =  sprintf( esc_html( get_post_meta('post_custom_date', $post->ID) ) );
            return $date;
        }
    }
?>

For custom meta With Acf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

<?php
    /**
    * @here 10 is Priority and 3 is Number of arguments to be passed
    */
    add_action( 'get_the_date','custom_date_callback', 10 , 3 );
    function custom_date_callback( $the_date, $format, $post ){
        if( get_post_type() === "custom_post_type" && is_singuler("custom_post_type") ){
            $date =  sprintf( esc_html( get_field('post_custom_date', $post->ID) ) );
            return $date;
        }
    }
?>

checkout all hooks hooks


For Refrence

https://developer.wordpress.org/reference/functions/get_the_date/ https://developer.wordpress.org/reference/functions/the_date/



If it is helpful and saves your valuable Time ⏱ please show your support 👇. Buy Me A Coffee
Buy me A Coffee, Thank you and canva ( For Beautiful designs ). Thanks for the reading 👍.
Built with Hugo
Theme Stack designed by Jimmy