I’m having a problem with PHP errors for dates. I have a field so that once a user is emailed a notice about their membership, the date gets stored so they don’t get emailed again. Initially this field is empty but I’m getting a lot of errors like this:
Warning: strtotime() expects parameter 1 to be string, object given in /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/advanced-custom-fields-pro/fields/date_picker.php on line 217 Warning: DateTime::createFromFormat() expects parameter 2 to be string, object given in /var/www/vhosts/domain.com/httpdocs/wp-content/themes/ddi-v1/functions-members.php on line 301
Line 301 has this:
$status->renewal_email_date = DateTime::createFromFormat('Ymd', get_field('field_557ff26b07d38', 'user_' . $user_id));
It seems that if no value is stored for the date field, an empty object is returned and this causes an error for the DateTime class. I’ve tried some code to check for an object but it still fails:
(!is_object(get_field('field_557ff26b07d38', 'user_' . $instructor->ID))) ? the_field('field_557ff26b07d38', 'user_' . $instructor->ID) : 'No date!';
Error:
Warning: strtotime() expects parameter 1 to be string, object given in /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/advanced-custom-fields-pro/fields/date_picker.php on line 217
Is this the correct behaviour?
Thanks