当前浏览:首页 / WordPress钩子 / get_the_date

apply_filters( 'get_the_date', string|int $the_date, string $format, WP_Post $post )

过滤发布文章的日期

datemore...

themore...


参数

$the_datestring|int
如果$format'U''G',则格式化日期字符串或Unix时间戳。
$formatstring
PHP日期格式。
$postWP_Post
post对象。


源码

查看源码 官方文档


更新日志

版本描述
3.0.0开始引入

使用示例

  • 示例1

    从Codex迁移的示例:

    以下是如何使用get_the_date过滤器修改名为“product”的文章类型的日期格式的基本示例:

    add_action( 'get_the_date', 'my_project_filter_publish_dates', 10, 3 );
    
    function my_project_filter_publish_dates( $the_date, $d, $post ) {
    	if ( is_int( $post) ) {
    		$post_id = $post;
    	} else {
    		$post_id = $post->ID;
    	}
    
    	if ( 'product' != get_post_type( $post_id ) )
    		return $the_date;
    
    	return date( 'Y-d-m - h:j:s', strtotime( $the_date ) );
    }