How can I create 'future' and 'past' parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?

add_filter( 'rest_events_query', 'filter_events_by_date_field', 999, 2 ); function filter_events_by_date_field( $args, $request ) { if ( ! isset( $request['filter_date'] ) ) { return $args; } $filter_date = sanitize_text_field( $request['filter_date'] ); $datetime = current_time('mysql'); if( $filter_date == 'future' ) { $filter_date_meta_query = array( 'key' => 'date', 'value' => $datetime, 'type' => 'DATETIME', 'compare' => '>=' ); } else { $filter_date_meta_query = array( 'key' => 'date', 'value' => $datetime, 'type' => 'DATETIME', 'compare' => '<' ); } if ( isset( $args['meta_query'] ) ) { …
Category: Web

How to pull date/time in french format for wordpress post?

I am working on a wordpress post in which I want the date/time in frech format as shown below: ENGLISH By FJ Published April 9, 2019 at 4:05 p.m. Last updated April 9, 2019 at 4:14 p.m. FRENCH Un texte de FJ Publié le 9 avril 2019 à 16 h 05 Mis à jour le 9 avril 2019 à 16 h 14 I have used the following code to pull the date/time in english/french for wordpress post: <strong><?php if(ICL_LANGUAGE_CODE=='en'){ ?> …
Category: Web

Separating publish date and last modified

Am I correct in understanding that the publish date and the modified date are actually the same thing under the covers in WP? We have a need to show “this article was last updated on”, which could be 2018 December. But the edit to put this date in our content could be done today, in April 2022. If we change the official modified date to be shown to the world (2018), by changing the publication date in WP, it doesn’t …
Category: Web

Change letters for day name

When I use this code the name of the day been writed with a small letter. get_the_time(strtotime($DateValue)), get_the_time('l d.m.Y H:i', $post) I want the name of the day looking like this: Monday, Sunday, Thursday etc. Now it look like this monday, sunday What do I do wrong ?
Category: Web

How to render a time-of-day string like '16:42' with a site's chosen time format?

I have a need to display a time-of-day value in a site's chosen time format. For example I have 16:42:18 and want to display it as 4:42 PM if the time_format option is g:i A, or 16:42:18 if the time_format is H:i:s. I need this to render data captured by HTML5's <input type="time"> form field. How to do this?
Category: Web

Displaying the Month and Year that a page was Created?

Question How can I display only the Month and Year that a page was created? Background I have a page that will get changes has a field that shows the month and year. It needs to be in Month and year format like "December 2013" Code I previously had this in my template, to display (for example) December 2013: <time><?php the_time('F Y') ?>:</time> But since it will only show up on a specific page I wrote this <?php if ( …
Category: Web

Display post links under month in paginated archive

I'd like to create an archive that lists posts under a month header. The months would just be plain text and the post titles, obviously, would link to the posts themselves! So: October 2013 Post title 1 Post title 2 September 2013 Post title 1 Post title 2 August 2013 Post title 1 Post title 2 . . . and, if possible, only show one year per page! So, uhhh, I guess it's paginated too. Is this possible? Probably. I've …
Category: Web

Running WP Cron on specific local time

The scenario is to run insert_post function every midnight (00:00) of local time. Must run daily on weekday. function add_daily_task(){ if((date('l', time()) != 'Saturday') || (date('l', time()) != 'Sunday')){ // insert post } } if(!wp_next_scheduled( 'add_daily_task_schedule')){ wp_schedule_event(time(), 'daily', 'add_daily_task_schedule'); // how should change time() to meet my local schedule? } add_action('add_daily_task_schedule', 'add_daily_task');
Category: Web

Hide publish date when update date

I was showing publish and update date together, but I'm trying to do it like this, hide the publish date if there is an update date <time datetime="<?php the_modified_time( 'c' ); ?>"> • Update Date: <?php the_modified_time( 'j F Y - H:i' ); ?> </time> <time datetime="<?php the_time( 'c' ); ?>"> • Publish Date: <?php the_time( 'j F Y - H:i' ); ?> </time> how can i do it using 'else if'
Category: Web

PHP function showing wrong time in WordPress

My local WordPress installation on XAMPP seems to have a wrong time setting. When I do date( 'Y-m-d H:i:s' ); I get 2017-02-21 10:46:43 as result. However my PCs time really is 2017-02-21 11:46:43, so my WordPress is one hour behind. Now I already did, what was recommended here and changed date.timezone in the php.ini to my timezone and restarted the apache afterwards, since I thought the problem might be cause by XAMPP. But still I get the wrong time …
Category: Web

Why do I need to set my PHP timezone when it's already set in WordPress?

I have WordPress set to Los Angles time in Settings > General. In my database I have a DATETIME column. When I use $dt = DateTime::createFromFormat('Y-m-d H:i:s', $value_from_db); and then $dt->format('n/j/y @ g:iA T'); it displays the timezone as "UTC". In functions.php if I add date_default_timezone_set( get_option('timezone_string') ); then $dt will output correctly with "PST". It works, but I didn't think I needed to explicitly set the timezone since I already set it in WordPress. Am I doing something wrong …
Category: Web

If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page

I need a way to inform visitors if the post published date or modified date is older than 1 year and if so, display a message on the post page. I have added an code to my content-single.php file, but without the desired results in terms of checking against both published and updated time. Example: if (strtotime($post->post_date) < strtotime('-1 year')){ echo 'Old Post'; } else { echo 'Not Old Post'; } Any ideas as I'm in the dark here..
Category: Web

How to detect and handle the time difference between server and user in WordPress?

I have to make a custom plugin for a WordPress website. In this plugin, I have to create a meta box for a post where I have a time and date field that decides that when the post will be expired and will be moved in the trash. but the problem is that website has 2 admins situated in two different time zones. One admin is in GMT+2 and one admin is in GMT+4 and the webserver is running according …
Category: Web

List taxonomy terms plus their latest post ordered by post date

I have the following code: $custom_terms = get_terms('columna'); foreach($custom_terms as $custom_term) { wp_reset_query(); $args = array('post_type' => 'post', 'posts_per_page'=>1, 'orderby' => 'date', 'order' => 'DESC', 'suppress_filters' => true, 'tax_query' => array( array( 'taxonomy' => 'columna', 'field' => 'slug', 'orderby' => 'date', 'order' => 'DESC', 'suppress_filters' => true, 'terms' => $custom_term->slug, ), ), ); $loop = new WP_Query($args); if($loop->have_posts()) { echo '<h4>'.$custom_term->name.'</h4>'; while($loop->have_posts()) : $loop->the_post(); echo '<a href="'.get_permalink().'">'.get_the_title().'</a><br>'.get_the_date().'<br>'; endwhile; } } It works, but it gets me something like this: * …
Category: Web

How to change the date and time in REST API for comments?

/** * Add a Formatted Date to the WordPress REST API JSON Post Object * */ add_action('rest_api_init', function() { register_rest_field( array('comment'), 'formatted_date', array( 'get_callback' => function() { return get_the_date(); }, 'update_callback' => null, 'schema' => null, ) ); }); This is not working for me. I am constantly getting the following in my JSON: "formatted_date":false," How can I show it in a format like: "28 November 2021, 15:00"?
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.