Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › The date in printed in english, how to show it in the site language?
- This topic has 7 replies, 2 voices, and was last updated 3 years, 4 months ago by
kyrian.
-
AuthorPosts
-
January 28, 2023 at 12:00 pm #41133
kyrian
ParticipantThe date in printed in english, I cannot find a way to show it in the site language (italian) – https://accademiainfinita.it/2/contenuti/
Oxygen builder prints the date in the site language by default – https://accademiainfinita.it/2/contenuti/societa/la-sociocrazia-prendere-decisioni-ascoltando-tutti/
What should I do to correct this?
Thanks
January 28, 2023 at 12:11 pm #41134kyrian
ParticipantApart from the language issue,
I’d like to convert the dates to human-readable formatI have used this code to make this change site wide, it works in all posts and pages but not for the search results
// Convert all dates to human-readable format function custom_time_ago() { return human_time_diff(get_the_time('U'), current_time('timestamp')) . ' fa'; } add_filter('the_time', 'custom_time_ago'); add_filter('get_the_date', 'custom_time_ago'); add_filter('the_modified_time', 'custom_time_ago');January 29, 2023 at 10:04 am #41138Ernest Marcinko
KeymasterHi,
On my end the dates are displayed correctly in the correct language, the plugin requests the date from WordPress core with the default date format set on the wordpress dashboard.
You can either use this option for custom date formats, or a custom code to change the date field for the results:
add_filter('asp_results', 'asp_custom_date_time'); function asp_custom_date_time($results) { foreach($results as $k=>&$r){ $r->date = human_time_diff(get_the_time('U', $r->id), current_time('timestamp')) . ' fa'; } return $results; }January 29, 2023 at 12:23 pm #41140kyrian
ParticipantThank you so much for providing the custom code!
I was able to solve the language issue as well.
Your support is legendary 🙂January 29, 2023 at 12:24 pm #41141Ernest Marcinko
KeymasterYou cannot access this content.
January 29, 2023 at 12:27 pm #41142kyrian
ParticipantThere is a little issue with the code you provided.
When I sue it, the date is being showed also for taxonomies (tags and categories) listed in search results.
see: https://www.screencast.com/t/UJnJmsbKC4Flive site: https://accademiainfinita.it/2/contenuti/
How can I modify the code, so the date shows only for posts/pages?
Thanks
January 29, 2023 at 12:28 pm #41144Ernest Marcinko
KeymasterTry:
add_filter('asp_results', 'asp_custom_date_time'); function asp_custom_date_time($results) { foreach($results as $k=>&$r){ if ( isset($r->post_type) ) { $r->date = human_time_diff(get_the_time('U', $r->id), current_time('timestamp')) . ' fa'; } } return $results; }January 29, 2023 at 12:31 pm #41145kyrian
Participantperfect, thank you 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.