Skip Navigation

[Resolved] CRED (French) date field problem since WP4.9.1?

This support ticket is created 7 years ago. There's a good chance that you are reading advice that it now obsolete.

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 5 replies, has 2 voices.

Last updated by Bruno Simon 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#594708

I am trying to: Save a CP via a CRED form, where the CP title is auto-generated and contains a date

Link to a page where the issue can be seen: hidden link
link to a page where the issue is not occuring: hidden link

I expected to see: hidden link: vendredi 22 décembre 2017 – TEST TEST TSET/?cred_referrer_form_id=2628

Instead, I got: hidden link

Hello, since I upgraded to WP4.9.1, it appears I experience issue with the way CRED registers certain dates; so far, december seems to be an issue.
Context: I am using the following function to extract a particular date from a CF and use it as part of the post title; said function is:

 //* Set locale to French 
setlocale (LC_TIME, "fr_FR");
//* CRED autotitle for CREATE auction listing
$auctiondate = get_post_meta($post_id, 'wpcf-auction-ending', true);//get the CF date from the CP
    $auctiondate2 = date('j F Y',$auctiondate);//change the standard date format to allow further conversion
    $auctionstamp = strftime("%A %d %B %Y", strtotime($auctiondate2));//convert timestamp to locale (French)
$title= $auctiontype. ': ' .$auctionstamp. ': ' .$auctionnumber;

Thanks for your help.

#594805

It seems like this code isn't running at all, because the new title doesn't include any of the ":" characters you add manually to the $title variable. Please add some debugging code and let me know what you find in the logs when you submit the CRED form:

function func_custom_post_title($post_id,$form_data) {
  	if ($form_data['id']==2628) {
    error_log('if form');
    $term_list = wp_get_post_terms($post_id, 'listing-type', array("fields" => "names","orderby"=>"term_id"));    
    $auctiontype = join("-",$term_list);
    $auctionnumber = get_post_meta($post_id, 'wpcf-auction-number', true);
    $auctiondate = get_post_meta($post_id, 'wpcf-auction-ending', true);
    error_log($auctiontype . ', ' . $auctionnumber . ', ' . $auctiondate);
    $listingdate = gmdate("Y-m-d H:i", $auctiondate);//convert timestamp to Y-m-d for changing post date to auction date and time   
    // Is this really necessary? strftime accepts a timestamp, which you already have in $auctiondate. There is no need to convert a timestamp into the same timestamp.
    $auctiondate = date('j F Y',$auctiondate);
    $auctionstamp = strftime("%A %d %B %Y", strtotime($auctiondate));//convert timestamp to locale (French)
    error_log('auctionstamp: ' . $auctionstamp);
    $term_list= wp_get_post_terms($post_id, 'car-brand', array("fields" => "names","orderby"=>"term_id"));
    $carbrand = join(" ",$term_list);
    error_log('carbrand: ' . $carbrand);
    $title= $auctiontype. ': ' .$auctionstamp. ': ' .$auctionnumber;
    error_log('title: ' . $title);    
    $args = array('ID' => $post_id, 'post_title' => $title, 'post_date' => $listingdate); //use auction date and time as post date
    error_log(print_r($args, true));
    wp_update_post($args);
    }
#594854

Hi Chris,
So I used your code in my function.php file but cannot seem to get a proper log file running. Still, using the standard WP debugging, I only get following notices when saving a new listing via the CRED form

Notice: wpdb::prepare est appelée de la mauvaise manière. La requête ne contient pas un nombre correct de substitutifs/placeholders (2) pour le nombre d'arguments proposés (3). Veuillez lire Débugger dans WordPress (en) pour plus d'informations. (Ce message a été ajouté à la version 4.8.3.) in /home/yellowsp/public_html/wp-includes/functions.php on line 4146

Notice: wpdb::prepare est appelée de la mauvaise manière. La requête ne contient pas un nombre correct de substitutifs/placeholders (1) pour le nombre d'arguments proposés (3). Veuillez lire Débugger dans WordPress (en) pour plus d'informations. (Ce message a été ajouté à la version 4.8.3.) in /home/yellowsp/public_html/wp-includes/functions.php on line 4146

About your remark:

$listingdate = gmdate("Y-m-d H:i", $auctiondate);//convert timestamp to Y-m-d for changing post date to auction date and time   
    // Is this really necessary? strftime accepts a timestamp, which you already have in $auctiondate. There is no need to convert a timestamp into the same timestamp.

It seems necessary because I am also using the date provided via CF wpcf-auction-ending as the post date as well; I tried without this conversion and WP did not recognize the format.
All that being said, I did not get your remark about the code not running at all since for some month (like November or January), I does work, as seen in this newly saved add: hidden link
Thanks for your time.

#595229

Hi Chris,
Having further Investigated the issue, it appears that the problem lies with the French month names containing an 'accent', i. e. 'décembre', février' and 'août' that cause the crash. I found some related info on this here: hidden link.
Knowing that, I still don't know how to solve this; as a patch, I will only inject figures in my slugs an titles, but that is not what the client wishes :/
If you have any idea...
Thanks.

#595392

Sorry, I'm not sure offhand. Unfortunately this falls outside the scope of the support we provide here in the forums as it is not directly related to any Toolset APIs. If I had to guess, there could be a problem with converting date strings with special characters into timestamps, but I'm not really sure. I would search for information about using PHP strftime with French, with accent characters, with a specific character set like UTF-8, etc. A quick search led me to this on stackoverflow:
https://stackoverflow.com/questions/8993971/php-strftime-french-characters

#595396

Hi Chris,
Indeed, it seems it's a mess and I'd probably better not try to generate slugs from words with accents.
Thanks for your time