Skip Navigation

[Gelöst] Date Cred generic field

This support ticket is created vor 2 Jahren, 5 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Dieses Thema enthält 14 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Pat vor 2 Jahren, 5 Monaten.

Assistiert von: Shane.

Author
Artikel
#2379603

Pat

Hello,

I try to use a date generic field inside a Cred and wants to use a custom date field as a placeholder.
Here is the code I'm using :
[php]
[cred_generic_field type='date' field='set-new-date' class="form-control" output="bootstrap"]
{
"required":0,
"persist":1,
"default":[wpv-post-date],
"validate_format":0
}
[/cred_generic_field]
</code
With this code, the cred field is not displayed. If I remoive the line "default":[wpv-post-date], then the field is displayed inside the form (but I don't have any placeholder).
Is there a way to display a placeholder inside a date cred generic field?

Regards
Pat

#2379667

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Pat,

Thank you for getting in touch.

I believe the default field only accepts a timestamp as a valid input.

So in order to set the field you will need to provide a timestamp to the field, example 1654614193 <- this is a timestamp of today.
versteckter Link

Thanks,
Shane

#2379699

Pat

Hi Shane,
I need to use à dynamic field for that : the date of the post which is in the current loop
Any idea?
Regards
Pat

#2379809

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Pat,

I've written up a custom shortcode that should allow you to convert the date to a timestamp
Add the following to your Toolset custom code settings at Toolset->Settings->Custom Code. Once you've done this please ensure that you've activated .

// Add Shortcode
function wp_get_timestamp( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'date' => '',
		),
		$atts
	);

	$date = $atts['date'];
	
	return strtotime($date);

}
add_shortcode( 'wp_get_timestamp', 'wp_get_timestamp' );

The code can be used like this with your default field.

 [wp_get_timestamp date='[wpv-post-date]']

Please let me know if this helps.
Thanks,
Shane

#2380065

Pat

Thanks Shane,

So, I could use it inside my generic field like this :

[cred_generic_field type='date' field='set-new-date' class="form-control" output="bootstrap"]
{
"required":0,
"persist":1,
"default":[wp_get_timestamp date='[wpv-post-date]'],
"validate_format":0
}
[/cred_generic_field]

Please confirm.
Regards
Pat

#2380313

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Pat,

That's correct. This is the correct format to be used.

Thanks,
Shane

#2380479

Pat

Hi Shane,

Just tested it and this is not working. In fact, the shortcode does not return anything. I placed this code in a post :
[wp_get_timestamp date='[wpv-post-date]'] - [wpv-post-date]
and what I got was : – 23 juillet 2020 (meaning the shortcode return was empty !
The function has been created thanks to the "parameter" section of Toolset.

Any idea?
Regards
Pat

#2380581

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Pat,

The custom shrotcode works on my end.
Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?

Please where applicable please provide me with a link to an example page where I can see the issue.

I've enabled the private fields for your next response.
Thanks,
Shane

#2380651

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Pat,

It seems the credentials aren't working.

Can you test them on your end and let me know if they work for you ?

Thanks,
Shane

#2381003

Pat

Hi Shane,

Sorry, that's now OK. You can try again.
The name of the file that contains the function in the Toolset parameters is : date-en-strtotime
The shortcode is placed inside a post : aaa
Be careful as this site is in production !
Regards
Pat

#2381441

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Pat,

This should be working now.

I had to change the format that the date is being passed into the shortcode. I managed to change it by using the format parameter like below.

[wpv-post-date format='d-m-yy']

Please let me know if this helps.
Thanks,
Shane

#2381579

Pat

Hi Shane,

That's working in a post but not in a Cred Form.
Can you have a look on the following form : Backoffice Modif ins enseignement
I have placed your shortcode but nothing is displayed?
The form is displayed in this page : versteckter Link
and you can see the form by clicking the "PAIEMENT" button in the top right of the page.
Regards
Pat

#2381611

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Pat,

This issue should now be resolved.

The problem now was that the date field couldn't handle the nested shortcode and the original reason why the date format had to change was because the strtotime() function couldn't convert the french date.

With these limitations I had to get creative and convert the french month to the english equivalent and then parse the date to a timestamp.

Here is the update function.

function wp_get_timestamp( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'date' => '',
        ),
        $atts
    );

    $date = explode(" ",$atts['date']);  
    $french_months = array('janvier'=>'january','février'=>'february','mars'=>'march','avril'=>'april',
                           'mai'=>'may','juin'=>'june','juillet'=>'july','aout'=>'august','septembre'=>'september','octobre'=>'october',
                           'novembre'=>'november','décembre'=>'december');
    $date[1] = $french_months[$date[1]];
    $english_date = implode(" ",$date);
    return strtotime($english_date);
 
}
add_shortcode( 'wp_get_timestamp', 'wp_get_timestamp' );

Please let me know if this helps.
Thanks,
Shane

#2381933

Pat

Hi Shane,

That's fully working now. Thanks for your support.
Regards
Pat

#2381935

Pat

My issue is resolved now. Thank you!