Skip Navigation

[Resolved] date conversion on custom fields

This thread is resolved. Here is a description of the problem and solution.

Problem:
I am using Conductor plugin to display data on a page. I have a types Date Field but its format is wrong (y-m-d format), how to convert date it as m-d-y format?

Solution:
- Add the follow custom JS code to change the date format, modify as needed:

jQuery(document).ready(function( $ ){
	// y-m-d to m-d-y
    jQuery(document).find('.custom-field-wpcf-date-of-baptism').each(function(index, element) {
        var old_format = jQuery(this).find('.custom-field-val').text();
		var old_format_array = old_format.split('-');
		var new_format = old_format_array[1] +'-'+old_format_array[2] +'-'+old_format_array[0];
		jQuery(this).find('.custom-field-val').text(new_format);
    });
});

==> Whereas ‘.custom-field-wpcf-date-of-baptism’ should be replaced with your custom field slug.

- You can install and use Simple Custom CSS and JS plugin if you don’t know where to paste above JS code:
https://wordpress.org/plugins/custom-css-js/

This support ticket is created 6 years, 10 months 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.

Our next available supporter will start replying to tickets in about 1.32 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 10 replies, has 2 voices.

Last updated by melF-2 6 years, 10 months ago.

Assisted by: Noman.

Author
Posts
#545492
types-CPT-fields.jpg
map-frmfields-cptfields.jpg
Grid-CPT-output.jpg

Hi,
I have created a custom post type (church user) and the related post fields (see attached pic)
CPT-fields.jpg. To enter the data I am using Formidable Forms Pro (see attached pic) map-frmfields. And the mapping works fine. The problem is with the date and the file upload (picture).
See attached Grid-CPT-output.

FF Pro saves the date in y-m-d format, and that is what is saved in the wpcf-date-of-baptism field and displayed. I am using the Conductor plugin to display data and it just outputs what it finds in the wpcf-fields that are mapped. I would like to have the date saved in the
wpcf-date-of-baptism field in m-d-y format!.

I am not a programmer so not sure how to approach this...

Thank You
Mel Fisher

#545585

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Mel,

Thank you for contacting Toolset Support. You can change date format using Types date filed shortcode
https://toolset.com/documentation/customizing-sites-using-php/functions/#date

Instead of the shortcode that you are using currently, please use this shortcode and it will give you correct m-d-y format:

[types field='event-date' style='text' format='m-d-Y'][/types]

==> Please replace ‘event-date’ with your date field name in the above shortcode.

Thank you

#545613

Hi Norman,

Thank you for the fast response...
I am not sure what you mean using the shortcode? Where would this line go? Why is the style= text for a date field?
[types field='event-date' style='text' format='m-d-Y'][/types]
Would I add this to the code snippets that I have?

I am using the Formidable Forms Pro to enter data not types? as described above. After Formidable Forms passes the date to
the wpcf-date-field I want the stored date for be in m-d-Y format.

Sorry but I am not a programmer.

Mel

#545717

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

First we need to get clear on your setup, as I understand you are doing something like this:
- Date Field is added using Types, into the Grid-CPT.
- That date field’s value is being updated using the Formidable form.
- Then the date field and content is shown on the page using Conductor plugin, using some shortcode.

Is all the above correct or there is something missing?

There is something wrong with the mapping of the date field as it is not getting correct value from the Types field. So you need to consult with the person who has done mapping for you, since the problem is in mapping and not the date field itself.

Alternatively, I would suggest to use Toolset Views plugin to display data on the page, instead of Conductor plugin. Then you will be able to display all fields correctly and will have control on correct date format. You will use the previously given shortcode in the View. Toolset Views also allows you to easily display posts, content, custom fields in list, grid and tables style as well.
https://toolset.com/home/views-create-elegant-displays-for-your-content/
https://toolset.com/documentation/user-guides/#views-topics

Thank you

#545873
Grid-CPT-output.jpg

Hi,

Thanks for the support and fast response.

Here are the steps of what I am doing:

1. Using Types I created a CPT and custom fields ( see fig CPT-fields.hjpg attached)
2. I created a form that maps the form fields to the wpcf-xxx fields in Types... And that works
fine!! (See map-frmfields.jpg)
3. I use Conductor plugin to display the data stored in wpcf-xxxxxx (types fields) and that works
fine too!!!

These 3 pieces are working fine.... I am NOT a programmer!

Problem: The forms program (Formidable Forms Pro) saves the date in Y-m-d format. I want Types to save the date (wpcf-date-of-baptism) in m-d-Y format! In the attached pic u can see the output is still in Y-m-d format......... 🙁

There must be a way to have a code snippet force types to save the date in specified format.

Views would work but it takes alot of code to get the output to look good when the Conductor plugin will use post, CPT, woo commerce, etc. and allow me to output data in grids, lists, etc very easy in minutes... Conductor works very good and soon will allow me to modify the output and
my problem will go away. Until then.....

Thanks
Mel

#545956

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Mel,

I need to look into your setup, please provide temporary access (WP-Admin and FTP Login info) to your site (possibly staging site). Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the Links to the [Form] Edit Screen, [Page] Edit Screen where you have inserted the form, CPT link or name, and also link to the page where you have created the date field.

Thank you

#546058

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Mel,

1. I can see that you are using Cloudflare CDN. Please clear / purge / delete Cloudflare cache completely. Clear out your website cache, plugins cache, server cache (if any), browser cache too. Also please temporarily disable CDN from Cloudflare control panel or set it as development mode, so it shows our changes on site.

2. I have tried to create a new conductor on your site, but I can not save the fields in the new conductor. I have also tried to test your conductor “test grid” but it does not effects on the page, even I have deleted the shortcode form the page but still it displaying the list on the front page.

I have recorded a small video for you: hidden link

Thank you

#546132

Hi Norman,

Thank you for looking at the site...

1. I put the Cloudflare CDN on pause... not sure why the page would not update good, so I created
a new page called toolset on the main menu.

2. I created a new Conductor query and works fine and date is still in Y-m-d format on new page.

3. is there a way so have a post wpcf-scrippet run after the date field is update and have that value stored in the db?

ACF plugin I think has this feature... but I would rather user Types.

Thanks
Mel

#546171

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for this, cache issue solved and site is working good now. I am working now and trying to do this with custom JS, I will update you with results soon.

Thank you

#546209

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Mel,

I have installed and activated the Simple Custom CSS and JS plugin and added the custom JS code to change the date format and now it is displaying the date in expected format m-d-y. Please check here: hidden link

jQuery(document).ready(function( $ ){
	// y-m-d to m-d-y
    jQuery(document).find('.custom-field-wpcf-date-of-baptism').each(function(index, element) {
        var old_format = jQuery(this).find('.custom-field-val').text();
		var old_format_array = old_format.split('-');
		var new_format = old_format_array[1] +'-'+old_format_array[2] +'-'+old_format_array[0];
		jQuery(this).find('.custom-field-val').text(new_format);
    });
});

JS code added here: hidden link

Thank you

#546297

Hi Norman,

Thank you for the support and solving the problem with a JS snippet.... That is the kind of solution I wanted. The Formidable Forms support suggested something similar but was not a generic solution like yours. Toolset support is super good and slowly I am learning to use it more.
That is why I am a lifetime owner of Toolset.

The date is now in the correct format.... and this will work for any plugin that I use with Types.
I will move my other CSS to the plugin that you installed because JS might be useful in other issues.

Now my last issue is the picture field but I will research that more and submit a ticket for that soon.

Thank You
Mel

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.