-
Notifications
You must be signed in to change notification settings - Fork 8
Date
The Date, Date-Time & Time fields allow users to pick a date/time through a jQuery date-picker.
There are no adjustable settings for those fields.
All of those fields use the format, set in WordPress. You can adjust it in Settings > General.
When you use the get_value
or get_sub_value
functions, the returned value will be a UNIX timestamp, which you can use with date functions like date_i18n
and etc.
If you use the_value
, get_the_value
, the_sub_value
and get_the_sub_value
functions, they will display/return a value based on your website's settings. If you prefer to change this format, please use a get_*
function in combiation with date_i18n
.
<h3>Date field:</h3>
<p>
Auto-formatted value:
<?php the_value( 'my_date_field' ) ?>
</p>
<p>
Manually formatted value:
<?php echo date_i18n( 'Y-m-d', get_value( 'my_date_field' ) ) ?>
</p>
<h3>Date-Time field:</h3>
<p>
Auto-formatted value:
<?php the_value( 'my_date_time_field' ) ?>
</p>
<p>
Manually formatted value:
<?php echo date_i18n( 'Y-m-d H:i', get_value( 'my_date_time_field' ) ) ?>
</p>
<h3>Time field:</h3>
<p>
Auto-formatted value:
<?php the_value( 'my_time_field' ) ?>
</p>
<p>
Manually formatted value:
<?php echo date_i18n( 'H:i', strtotime( '2017-01-01 ' . get_value( 'my_time_field' ) ) ?>
</p>
As you can see the only exception is the value of the Time field. It will always return a 24-hour format H:i
string, which consists of an hour and a date. In order to use this value with the date_i18n
function, you need to convert the time to an actual timestamp. To do that, we are using a fake date and processing the value through strtotime()
.
Quick start
- Creating fields and using their values
- Installation
- Administration interface
- Using the PHP API
- Container Settings
Locations
- Overview & Usage
- Post Type
- Options Page
- Taxonomy
- Comment
- User
- Widget
- Shortcode
- Menu Item
- Attachment
- Customizer
Fields
- Fields
- Text
- Textarea
- WYSIWYG
- Password
- Checkbox
- Select
- Multiselect
- Image Select
- File
- Image
- Audio
- Video
- Gallery
- WP Object
- WP Objects
- Link
- Date
- DateTime
- Time
- Color
- Font
- Icon
- Map
- Embed
- Number
- Sidebar
- Complex
- Repeater
- Layout
- Section
- Tab
- Message
Features
- Adding fields to the Customizer
- Conditional Logic
- Front-End Forms
- Administration columns
- Import and Export
- REST API
- JSON Synchronization
- Yoast SEO
Ultimate Post Types
Functions and API
Tutorials