Display posts of the last 7 days

In addition to birgire’s solution, as of WordPress 3.7, you can use Date parameters. Your arguments would look like this to filter posts from the last 7 days: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, // Using the date_query to filter posts from last week ‘date_query’ => … Read more

How to get post creation date?

The post_date and post_date_gmt serves as the date that the post was created. For scheduled posts this will be the date on which the post is scheduled to be published. There is no reliable native method to determine the date when a scheduled post was added. For scheduled posts, you can try the post_modified or … Read more

WP_Query orderby date not working

This will definitely work….It worked for me… $username = get_the_author_meta( ‘login’, $author_id ); $args = array( ‘post_type’ => ‘any’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘suppress_filters’ => true, ‘tax_query’ => array( array( ‘taxonomy’ => ‘author’, ‘field’ => ‘name’, ‘terms’ => $username ) ) ); $query = new WP_Query( $args );

How to get the post publish date outside the loop?

get_the_date must be used inside the Loop. For outside the loop use get_the_time. $posts = get_posts(array(‘numberposts’=>-1)); //Get all published posts foreach ($posts as $post){ echo get_the_time(‘Y-m-d’, $post->ID); //Echos date in Y-m-d format. } Consider replacing ‘Y-m-d’ in this example with get_option(‘date_format’) as this will display the date as per your date format setting in wp-admin.

Display user registration date

get_current_user_id() give you the user id of the logged in user. And that is: you. You have to get all users: <?php $users = get_users(); foreach( $users as $user ) { $udata = get_userdata( $user->ID ); $registered = $udata->user_registered; printf( ‘%s member since %s<br>’, $udata->data->display_name, date( “M Y”, strtotime( $registered ) ) ); }

How to get date for each post?

I ran into the same problem several times, following changes worked for me in the past: while (have_posts()) : the_post(); //some html <li class=”icon-date”><?php echo get_the_date( ‘Y-m-d’ ); ?></li> <li class=”icon-time”><?php the_time( ‘H:i:s’ ); ?></li> Instead of the_date(), use get_the_date(). The only thing to be aware of, is that values returned by get_the_date() have to … Read more

How to get posts published between a date and today?

UPDATE December 23 2014 There is a better method using date_query property of WP_Query class: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array( ‘post-format-image’ ) ) ), ‘cat’ => ‘-173’, ‘post_status’ => ‘publish’, ‘date_query’ => array( ‘column’ => ‘post_date’, ‘after’ => ‘- 30 days’ … Read more