WordPress returns a wrong date

As mmm said, wp stores all dates&times in gmt, but will show times as per the setting timezone. So you can cgange the timezone without the history needing to be updated. I prefer to use the php datetime when working with time. Gives better control and flexibility, eg if you want to show events in … Read more

Display commenter’s registration date on comments?

In your wp_list_comments callback function, you can call get_userdata to get any additional comment author data: $userdata = get_userdata( $comment->user_id ); echo ‘Registered: ‘ . $userdata->user_registered; // format the date // Sunday January 13th 2013 echo ‘Registered: ‘ . date( ‘l F jS Y’, strtotime( $userdata->user_registered ) );

Count days from registration date to today

I am using this answer from StackOverflow as a basis which using functions from PHP 5.2.2 The main issue is that human_time_diff() doesn’t always return days, nor does it have a parameter on what to return. This function just returns how long they have been registered, whether it’s days, weeks, months, or years. I believe … Read more

How to display an icon when a new post is published and then remove it when a specific time past?

Filter the content of post_class(): add_filter( ‘post_class’, function( $classes ) { if ( is_singular() ) return $classes; // now minus last mod time in seconds $diff = time() – mysql2date( ‘U’, $post->post_date ); if ( DAY_IN_SECONDS <= $diff ) $classes[] = ‘new-post’; return $classes; }); Now, in your loop, use post_class(), and you get an … Read more

How can I hide posts that are over 2 years old

You can use the pre_get_posts hook to modify the main query: add_action( ‘pre_get_posts’, ‘filter_old_posts’ ); function filter_old_posts($query){ if( !is_admin() && $query->is_main_query()){ add_filter(‘posts_where’, $callback = function( $where=””){ $where .= ” AND post_date > ‘” . date(‘Y-m-d’, strtotime(‘-2 years’)) . “‘”; return $where; }); add_filter(‘getarchives_where’, $callback ); } } This will filter the main query posts to … Read more

Retrieve taxonomy terms in order of their post’s date?

I would use the terms_clauses filter, and then just use get_terms(): function wpse147412_order_terms_by_post_date( $pieces, $taxonomies, $args ) { global $wpdb; if ( ‘post_date’ !== $args[‘orderby’] ) { return $pieces; } $args = wp_parse_args( $args, array( ‘post_types’ => ‘post’ ) ); $pieces[‘fields’] = ‘DISTINCT ‘ . $pieces[‘fields’]; $pieces[‘join’] .= ” JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id … Read more

month name translation

Use date_i18n(): date_i18n( ‘Y. F j.’, strtotime( get_the_time( “Y-m-d” ) ) ); From the function’s description: Retrieve the date in localized format, based on timestamp. If the locale specifies the locale month and weekday, then the locale will take over the format for the date. If it isn’t, then the date format string will be … Read more

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