Created
March 14, 2024 09:47
-
-
Save lunaluna/416603415c1ea3afd15070e1ea11f90f to your computer and use it in GitHub Desktop.
【WordPress】投稿の Datetime を取得(出力)したいとき
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// `get_post_datetime` 関数を利用する | |
$datetime = get_post_datetime( $post, 'date', 'gmt' ); | |
/** | |
* refs : https://developer.wordpress.org/reference/functions/get_post_datetime/ | |
*/ | |
// DateTime オブジェクトが返るので、W3C 形式で整形する | |
$datetime_attribute = $datetime->format( DateTime::W3C ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
get_post_datetime