Problem: I would like to format a timestamp stored in a non-Types custom field, but the wpv-post-field shortcode does not seem to work.
Solution: The wpv-post-field shortcode is meant to be used to display raw values from the database, not formatted values. The Types field shortcode can show formatted dates, but usually not from non-Types fields. You can use a custom shortcode like this:
// format a postmeta field timestamp to return a date function format_meta_timestamp_date_func($atts) { $a = shortcode_atts( array( 'format' => 'Y-m-d H:i:s', 'slug' => '', 'id' => 0 ), $atts ); $timestamp = get_post_meta( $a['id'], $a['slug'], true ); if ( !$timestamp ) return; $date = date($a['format'], $timestamp); return $date; } add_shortcode( 'format-meta-timestamp-date', 'format_meta_timestamp_date_func');
Then use the shortcode like this:
[format-meta-timestamp-date id="12345" format="Y-m-d H:i:s" slug="_sale_price_dates_from"][/format-meta-timestamp-date]
Replace 12345 with the post ID or a wpv-post-id shortcode.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 5 months ago.
Assisted by: Christian Cox.