fixed error when retrievieng acf dates with format
This commit is contained in:
@@ -40,8 +40,22 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
* 118 : ../../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-value-functions.php
|
||||
*
|
||||
* we can either use filter 'acf/load_value' or 'acf/pre_load_value'
|
||||
* - 'acf/pre_load_value' :
|
||||
* it fires first, and will short-circuit the function to get the value
|
||||
* it is useful to force the acf_date value to be always the same,
|
||||
* otherwise acf uses some kind of cach system,
|
||||
* so the value would be evaluated once then it would always be the same on the page : maybe it's alright ?
|
||||
* - 'acf/load_value' :
|
||||
* using this filter, the value is cached, as explained above
|
||||
* - note : the first argument '$value' is actually a little misleading :
|
||||
* - in case of the second filter,
|
||||
* it is indeed tha value that has already been retrieve and that we can override
|
||||
* - but for the first filter, it is actually 'null',
|
||||
* and if returned it will let the function go on to try to retrieve the value
|
||||
*
|
||||
*/
|
||||
function try_format_acf_date($value, $post_id, $field) {
|
||||
function try_get_acf_date($value, $post_id, $field) {
|
||||
$acf_date_class = Fbpatch::ACF_DATE_CLASS;
|
||||
if ($field['type'] !== 'date_picker') {
|
||||
return $value;
|
||||
@@ -51,13 +65,18 @@ function try_format_acf_date($value, $post_id, $field) {
|
||||
}
|
||||
|
||||
$acf_date = Fbpatch::get_acf_date($post_id, $field['key']);
|
||||
//error_log("acf_date: " . json_encode($acf_date));
|
||||
if ($acf_date === false) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $acf_date;
|
||||
}
|
||||
add_filter('acf/load_value', __NAMESPACE__.'\try_format_acf_date', 10, 3);
|
||||
add_filter('acf/load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
|
||||
//add_filter('acf/pre_load_value', __NAMESPACE__.'\try_get_acf_date', 10, 3);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user