admin管理员组文章数量:1277888
/**
* Add a Formatted Date to the WordPress REST API JSON Post Object
*
*/
add_action('rest_api_init', function() {
register_rest_field(
array('comment'),
'formatted_date',
array(
'get_callback' => function() {
return get_the_date();
},
'update_callback' => null,
'schema' => null,
)
);
});
This is not working for me. I am constantly getting the following in my JSON:
"formatted_date":false,"
How can I show it in a format like: "28 November 2021, 15:00"
?
/**
* Add a Formatted Date to the WordPress REST API JSON Post Object
*
*/
add_action('rest_api_init', function() {
register_rest_field(
array('comment'),
'formatted_date',
array(
'get_callback' => function() {
return get_the_date();
},
'update_callback' => null,
'schema' => null,
)
);
});
This is not working for me. I am constantly getting the following in my JSON:
"formatted_date":false,"
How can I show it in a format like: "28 November 2021, 15:00"
?
1 Answer
Reset to default 1In general I would be careful modifying existing endpoints, but you could try using the object passed into the callback, e.g.:
'get_callback' => function( $object ) {
return date_i18n( __( 'j. F Y, H:i', 'wpse' ), strtotime( $object['date'] ) );
},
本文标签: How to change the date and time in REST API for comments
版权声明:本文标题:How to change the date and time in REST API for comments? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741216784a2360195.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论