“is_new_day()” alternative for years?

You could create a helper function that returns a year number only once per year: function get_unique_year( $post_id = 0 ) { static $last = 0; $post_id || $post_id = get_the_ID(); $year = get_the_time( ‘Y’, $post_id ); if ( $year === $last ) return; $last = $year; return $last; } Then fetch your posts and … Read more

php console log speed [closed]

If you will write inside the console of your browser, then use one of a lot of helpers or use a small custom function in php. The follow function is easy to use and log inside the console of the browser. if ( ! function_exists( ‘debug_to_console’ ) ) { /** * Simple helper to debug … Read more

How to get date using timezone saved in options? [duplicate]

I use this: $mytheme_timezone = get_option(‘timezone_string’); date_default_timezone_set($mytheme_timezone); in my themes functions.php. For me this has worked without any warnings. I’ve also tested whether my script is in different timezone than php.ini: if (strcmp($mytheme_timezone, ini_get(‘date.timezone’))){ echo ‘Script timezone differs from ini-set timezone.’; } else { echo ‘Script timezone and ini-set timezone match.’; } Please improve this … Read more

Advanced custom fields: Customise date picker’s start date (need to choose year 1500 onwards) [closed]

You can do this by customizing the plugin. You’ll want to find timepicker.js in /wp-content/plugins/acf-field-date-time-picker/js/timepicker.js And change line 21: , yearRange: “-100:+100” to your preferred range, for example: , yearRange: “-500:+100” This gives you a dropdown that, by default, goes back 500 years and forth 100, from the current year. Or you can hardcode a … Read more

What are the “U” and “G” time formats?

The U and G are not WordPress specific. get_post_time() is using the same datetime formats as the default PHP date method. Here is the documentation for all of the formats: https://www.php.net/manual/en/function.date.php Specific to the question: U is Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) G is 24-hour format of an hour without … Read more

Displaying year, month and day archives differently

Conditional tags FTW. is_month() : Currently viewing a monthly archive is_day() : Currently viewing a single day archive is_year() : Currently viewing a yearly archive is_time() : Currently viewing a time-based archive (hourly, minute, or even seconds) So to test for each of these conditions, add something like this to your archive.php (or whatever template … Read more

Calculate future date

try $future_timestamp = strtotime(‘+1 week’, get_the_date(‘Y-m-d’)); echo date(‘Y-m-d’, $future_timestamp); or $future_timestamp = get_the_date(‘U’) + (60 * 60 * 24 * 7); echo date(‘Y-m-d’, $future_timestamp);