Skip to content

Instantly share code, notes, and snippets.

@lunaluna
Created March 14, 2024 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunaluna/416603415c1ea3afd15070e1ea11f90f to your computer and use it in GitHub Desktop.
Save lunaluna/416603415c1ea3afd15070e1ea11f90f to your computer and use it in GitHub Desktop.
【WordPress】投稿の Datetime を取得(出力)したいとき
<?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 );
@lunaluna
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment