Skip Navigation

[Résolu] Styling of fields from a dynamic source

This support ticket is created Il y a 4 années et 3 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Marqué : 

Ce sujet contient 9 réponses, a 2 voix.

Dernière mise à jour par boW-2 Il y a 4 années et 3 mois.

Assisté par: Shane.

Auteur
Publications
#1763201

Tell us what you are trying to do?
I want to style a date from a post field. I am do a Toolset loop over a Custom Post Type. In the Post type I have the date represented in two fields: 1) string (format: YYYY-MM-DD), 2) standard unix timestamp. I want the display on my page to look like "12. Oct".

When I am adding either of the two fields I dont see any date styling options in the editor (only font, color etc).

I am using Gutenberg editor.
I am not familiar with development.

any suggestions? Your support is highly appreciated!

#1763449

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Screenshot 2020-09-01 at 9.24.58 AM.png

Hello,

Thank you for getting in touch.

When you are using the single field block to display your date field, there is field setting option that can allow you to setup your custom format. See Screenshot

In your case to get "12. Oct" you will use the custom format "j. M"

Please let me know if this helps.
Thanks,
Shane

#1764189

Hi Shane - thanks for your reply.

Unfortunately this isn't solving my problem. My date (given from another plugin) is either of string type or a standard unix time stamp. None of the two fields provide field settings shown in your screenshot.

BR Bo

#1764327

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hello,

Given that this is a custom field not from types then you won't get these options. You will need to create a shortcode to parse the date in the format that you want.

Doesn't the custom field plugin that you are using provide a way to retrieve the field value and format the date ? Which plugin are you using the create this custom field.

Please let me know.
Thanks,
Shane

#1765053

Hi Shane - thanks for you reply.

The custom fields come from a plugin called FooEvents. It is an add-on to WooCommerce (selling tickets for events). The two date fields are given by the plugin. And I dont know how to massage the date information with a shortcode into date format so it can be presented in the layout I want (I'm not familiar with wp development)

I hope you can advise a work-around for my problem

#1765371

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hello,

Can you try this field to retrieve the date field value and let me know exactly the value that you get from the database.

[wpv-post-field name='field-slug']

I've written a custom shortcode that helped a customer in the past with formatting their date information but I need to know what exactly is returned from the database. Replace field-slug with the correct slug of the custom date field.

Thanks,
Shane

#1765381

Hi Shane,

The "string" field returns : "2020-07-29"
The unix timestamp field returns: 1595980800

#1765419

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hello,

For the Unix timestamp field you can use this custom shortcode.

function wp_convert_timestamp( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'timestamp' => '',
            'format' => '',
        ),
        $atts
    );
  $date="";
  if(!empty($atts['timestamp'])){
    $date = date($atts['format'], $atts['timestamp']);
     }
     
    return $date;
 
}
add_shortcode( 'wp_convert_timestamp', 'wp_convert_timestamp' );

Add this custom snippet to the Toolset custom code in Toolset -> Settings -> Custom Code and activate it. Once you've done this you can use the shortcode like this.


[wp_convert_timestamp timestamp="[wpv-post-field name='field-slug']" format="j. M"]

Please try this and let me know if your date format comes out correctly.

Thanks,
Shane

#1765485

Shane - you are my hero - it is working !

Big thanks

#1765487

My issue is resolved now. Thank you!