• Resolved skylex69

    (@skylex69)


    Hi,

    Is there a way to override the default date format we get from data.formatted.postedDate in a custom template?

    Ideally, I would like to make some custom function to show “X hours ago” for recent posts and the default format, but with translated months, for older posts. If it’s not possible to use a custom function, I could be satisfied with a date format like d/m/Y.

    Thanks and best regards

    • This topic was modified 1 year, 7 months ago by skylex69.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter skylex69

    (@skylex69)

    Response to myself, in case somebody else wants to do the same:

    new Date(data.post_date).toLocaleDateString("fr-FR", {year: "numeric", month: "long", day: "numeric"})

    Plugin Contributor digamberpradhan

    (@digamberpradhan)

    Hi @skylex69,

    Yes, you can change the date like you’ve done here. Or you can go to
    Settings > General
    And change the date format from there.

    The date is designed to be changed according to how date format is selected there.

    Thread Starter skylex69

    (@skylex69)

    The date format was the same as this setting indeed, but the months were not translated in the search results, whereas it is everywhere else in this WordPress.

    Plugin Contributor digamberpradhan

    (@digamberpradhan)

    @skylex69 ,

    Can you please let me know which language you’re using.
    I will run some tests and see what i can do to change this.

    Thread Starter skylex69

    (@skylex69)

    The language is French. Thanks

    Plugin Author CodeManas

    (@codemanas)

    @skylex69 we have updated the code for date display in version 1.9.0.
    This will be a breaking change and will require users to reindex the collection to use the new system. The update now uses WordPress date format by default and will understand the locale correctly as well.

    Thread Starter skylex69

    (@skylex69)

    Ok great, thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Override date format in template’ is closed to new replies.