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

Loop through all posts in a certain year

You will have to run a custom query for that. Here is the query for displaying posts from a particular year. I have used year 2012 as an example. $args = array( ‘post_type’ => ‘post’, ‘ignore_sticky_posts’ => 1, ‘year’ => ‘2012’, ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( … Read more

Way to display “Yesterday”, “Today”

It took me less than a minute of asking the googles (or bing, or duck) to find this answer: https://stackoverflow.com/questions/3454258/php-date-yesterday-today The accepted answer has the code you want to use (or will give you a starting point). (And this is not really a WordPress question…it’s a PHP question. PHP questions belong on the Stack Overflow … Read more

Meta Query for specific months

You need the 2 digit month number that you want to query on and then use the code below. This should be easy with php (for example, see this post). In the code below $month is the number of the month in a 2 digit format, eg March would be 03. $start_date = date(‘Y’.$month.’01’); // … Read more

Display page only if user registered before a specific date

This is a basic function to get the current user and compare it with a custom DateTime to see if the user registered earlier or later: function wpse_219284_registered_before( $date_time ) { $user = wp_get_current_user(); $registered_before = false; if ( $user instanceof WP_User ) { $registered = new DateTime( $user->data->user_registered ); $limit = new DateTime( $date_time … Read more

Change date from 2015/02/23 to “1 min ago”

Here you go. This goes in functions.php This changes the time on your website everywhere. Now you can keep using <?php echo get_the_date(); ?> in your loop or theme files. // Relative date & time function wpse_relative_date() { return human_time_diff( get_the_time(‘U’), current_time( ‘timestamp’ ) ) . ‘ ago’; } add_filter( ‘get_the_date’, ‘wpse_relative_date’ ); // for … Read more

How to display all posts with today’s same month and day only?

You can achieve this with the date_query parameters added in version 3.7. To modify the main query on your posts page before it is run and apply the date_query parameters, we use the pre_get_posts action: function historical_posts_list( $query ){ if( $query->is_home() && $query->is_main_query() ){ $date_query = array( array( ‘month’ => date( ‘n’, current_time( ‘timestamp’ ) … Read more