Last active
March 14, 2018 23:43
-
-
Save tripflex/8c980a4980d6e67c8ffe1fe296b4fa38 to your computer and use it in GitHub Desktop.
Custom date format for output when using WP Job Manager Field Editor (example uses job_expires meta key)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ^ the <?php above should only be in your functions.php file ONCE, at the top | |
// The filter is field_editor_output_as_value_METAKEY | |
// where you need to replace METAKEY with the actual meta key you want to filter the output for | |
// .... as you can see below you can also add multiple filters using the same function. | |
//add_filter( 'field_editor_output_as_value_METAKEY', 'my_custom_format_value_as_date_format' ); | |
//add_filter( 'field_editor_output_as_value_ANOTHERMETAKEY', 'my_custom_format_value_as_date_format' ); | |
// This example is used for the "job_expires" meta key | |
add_filter( 'field_editor_output_as_value_job_expires', 'my_custom_format_value_as_date_format' ); | |
/** | |
* General function to output HTML for custom fields | |
* | |
* @author Myles McNamara | |
* @url https://plugins.smyl.es | |
* | |
* @param $value The value before it is output on the listing | |
*/ | |
function my_custom_format_value_as_date_format( $value ){ | |
if( empty( $value ) ) return $value; | |
// Convert to epoch from any type of date format | |
$timestamp = strtotime( $value ); | |
// See http://php.net/manual/en/function.date.php for available formats | |
$formatted_date = date_i18n( "j F Y", $timestamp ); | |
return $formatted_date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment