After wp_insert_post(), date_i18n() and date() outputs are adjusted to GMT

If you do not pass a date to wp_insert_post(), get_gmt_from_date() is called. And look at that function’s content: function get_gmt_from_date($string, $format=”Y-m-d H:i:s”) { preg_match(‘#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#’, $string, $matches); if ( ! $matches ) return date( $format, 0 ); $tz = get_option(‘timezone_string’); if ( $tz ) { date_default_timezone_set( $tz ); $datetime = date_create( $string ); if ( … Read more

About Time conditionals

Here is how it works for me with minor changes: global $post; $post_created = strtotime($post->post_date); $sixMonthsAgo = strtotime(‘-6 months’); $human_time=”hace “. human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ); $mobile = wp_is_mobile(); if ($post_created > $sixMonthsAgo && $mobile) { the_time(‘j. M .Y’); } elseif( $post_created > $sixMonthsAgo && !$mobile) { the_time(‘j. F .Y’); } else { echo $human_time; } … Read more

Add a link to display posts with a specific tag within a date range

Check out wp_get_archives(). As described by the Function Reference linked to above, “This function displays a date-based archives list. This tag can be used anywhere within a template.” It gives several examples of how you can use the function, including if you wish to use a dropdown rather than listing every archive. By default this … 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

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

Display post date as 04/26/2013

the_time( ‘m/d/Y’ ); or the_date( ‘m/d/Y’ ); Note, the_date() will not print the same value twice. If a second post would get the same output you get nothing. If your theme doesn’t set a fixed value, like Twenty Twelve … get_the_date() … then the format is taken from your settings in Settings/General Settings: You can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)