admin管理员组文章数量:1122832
So I am making changes to a clients website and currently they have an events post type with some custom fields that allow them to set an events end date/time and the events timezone.
The custom fields setup:
- Start Date and Time: text input / saves as php format
U
- End Date and Time: text input / saves as php format
U
- Timezone: select field / saves as string (e.g.
GMT
/BST
)
And then on the front end their current wp_query is:
$events_query = new WP_Query([
'post_type' => 'events',
'meta_key' => 'start_date_and_time',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => [
[
'key' => 'end_date_and_time',
'value' => date('U'),
'compare' => '>=',
'type' => 'NUMERIC'
]
]
]);
But this is not taking into account the timezone set in the backend compared to the timezone of the user.
Any help would be great.
Thanks.
So I am making changes to a clients website and currently they have an events post type with some custom fields that allow them to set an events end date/time and the events timezone.
The custom fields setup:
- Start Date and Time: text input / saves as php format
U
- End Date and Time: text input / saves as php format
U
- Timezone: select field / saves as string (e.g.
GMT
/BST
)
And then on the front end their current wp_query is:
$events_query = new WP_Query([
'post_type' => 'events',
'meta_key' => 'start_date_and_time',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => [
[
'key' => 'end_date_and_time',
'value' => date('U'),
'compare' => '>=',
'type' => 'NUMERIC'
]
]
]);
But this is not taking into account the timezone set in the backend compared to the timezone of the user.
Any help would be great.
Thanks.
Share Improve this question asked Jun 23, 2016 at 9:45 Levi ColeLevi Cole 6232 gold badges6 silver badges13 bronze badges1 Answer
Reset to default 0date()
PHP functions returns the value of time()
PHP functions in the specified format. time()
use server local time. If you want to get date/time based of WordPress configuration, you could use current_time()
, a WordPress function, instead of native PHP functions.
// 'timestamp' = Unix Timestamp or 'U' PHP time format
$current_time = current_time( 'timestamp' );
本文标签: Query events post type after current date and timezone
版权声明:本文标题:Query events post type after current date and timezone 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304329a1932196.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论