admin管理员组文章数量:1129647
In my search.php file i have a loop which succesfuly gives list of search query.
global $wp_query;
$total_results = $wp_query->posts;
if ( $total_results ) :
foreach ( $total_results as $tr ) :
//(...)
endforeach;
endif;
But there is something wrong with date time in results because the_time()
function displays a wrong date for all listed posts. Here is what i get:
the_time( 'j F Y, G:i' ); // --> 7 NOVEMBER 2023, 20:00 (don't know what kind a date is that)
echo get_the_date( 'j F Y, G:i' ); --> 7 NOVEMBER 2023, 20:00
echo $tr->post_date; // --> 2023-10-13 23:00:47 (proper publish date)
Is my query is right? Apart from date, meta data of all listed posts are correct (title, author etc.).
In my search.php file i have a loop which succesfuly gives list of search query.
global $wp_query;
$total_results = $wp_query->posts;
if ( $total_results ) :
foreach ( $total_results as $tr ) :
//(...)
endforeach;
endif;
But there is something wrong with date time in results because the_time()
function displays a wrong date for all listed posts. Here is what i get:
the_time( 'j F Y, G:i' ); // --> 7 NOVEMBER 2023, 20:00 (don't know what kind a date is that)
echo get_the_date( 'j F Y, G:i' ); --> 7 NOVEMBER 2023, 20:00
echo $tr->post_date; // --> 2023-10-13 23:00:47 (proper publish date)
Is my query is right? Apart from date, meta data of all listed posts are correct (title, author etc.).
Share Improve this question edited Nov 22, 2023 at 19:27 X9DESIGN asked Nov 22, 2023 at 19:22 X9DESIGNX9DESIGN 1699 bronze badges1 Answer
Reset to default 1All the date functions reference the global $post
variable, but from your code the $post
variable is not being used, so that's why the date is wrong.
Try this (untested):
foreach ( $total_results as $tr ) {
echo get_the_time( 'j F Y, G:i', $tr );
}
本文标签: loopDifferent date time in results of search
版权声明:本文标题:loop - Different date time in results of search 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736741086a1950511.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论