• Resolved Maxon

    (@mwww_31)


    Hi, we’re building a website for training courses.

    Each training course has many sessions. For each session, there is the start date (attribute : “wpcf-date-de-debut-de-la-formation”), the end date (attribute : “wpcf-date-de-fin-de-la-formation”), and the location (attribute : “wpcf-lieu-de-la-formation”).

    The form is a registration form, where you can choose a session for a training course.

    In CF7, here is the shortcode of the select field :

    [post_select post_select-474 posts-number:-1 publish post-type:calendrier-formation tax-relation:OR value-field:title orderby:title order:DESC “%title% : du %wpcf-date-de-debut-de-la-formation% au %wpcf-date-de-fin-de-la-formation% – à %wpcf-lieu-de-la-formation%”]

    Expected display output in the select dropdown :

    (Option 1)
    Formation Dirigeant / Gestionnaire : du 5 novembre 2018 au 7 décembre 2018 – à Metz, France

    (Option 2)
    Formation Conseiller funéraire : du 6 mars 2019 au 13 mars 2019 – à Coulaines, France

    Actual display output :

    (Option 1)
    Formation Dirigeant / Gestionnaire : du 1 551 830 400 au 26 novembre 5200 – à Metz, France

    (Option 2)
    Formation Conseiller funéraire : du 26 novembre 6000 au 1 544 140 800 – à Coulaines, France

    It looks life the label doesn’t handle date format. You can see the issue in the provided link.

    Best regards, Maxime

    • This topic was modified 6 years, 3 months ago by Maxon.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Markus Wiesenhofer

    (@markusfroehlich)

    Hello Maxon,
    how are the date meta fields “wpcf-date-de-fin-de-la-formation” stored in the database?
    With a timestamp or MySQL format?

    Best regards

    Thread Starter Maxon

    (@mwww_31)

    Good evening Markus, all the date meta fields are stored as timestamps in the database. I guess I’ll need to find a way to convert those timestamps values into date or datetime.
    Should I use FROM_UNIXTIME() and CAST() functions in a query to solve this ?

    Best regards, Maxime

    Plugin Author Markus Wiesenhofer

    (@markusfroehlich)

    Hello Maxon,
    you can modify the meta output with the “wpcf7_{$tag_name}_formatted_post_meta” filter.

    add_filter("wpcf7_{$tag_name}_formatted_post_meta", "wpcf7_format_meta_value", 10, 4);
    
    function wpcf7_format_meta_value($meta_values, $post_id, $meta_key, $post_meta_raw)
    {
    	if($meta_key === 'wpcf-date-de-fin-de-la-formation')
    	{
    		$meta_values = array();
    		
    		foreach($post_meta_raw as $post_meta_value)
            {
    			if(is_numeric($post_meta_value)) {
    				$meta_values[] = date_i18n(get_option('date_format'), $post_meta_value);
    			}
    		}
    	}
    	
    	return $meta_values;
    }

    Best regards
    Markus

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Date attribute in select field display bug’ is closed to new replies.