Query posts from current year

You just need get current date and add it on data_query in wp_query, Look this: <?php $getdate = getdate(); $args = array( ‘date_query’ => array( array( ‘year’ => $getdate[“year”] ), ), ); $query = new WP_Query( $args ); ?> and then use loop: <?php if ( $query->have_posts() ): while ( $query->have_posts() ) : $query->the_post(); the_title(); … Read more

Uploading DB to server from local is not matching the post dates

WordPress uses the date_default_timezone_set() function to set the server timezone. This is based on the timezone offset setting under Settings->General. Check your setting to make sure it matches your timezone at: http://yourdomain.com/wp-admin/options-general.php If changing your timezone via the setting doesn’t work, there’s probably nothing you can do to change this without touching your server configuration. … Read more

WordPress Custom Query to show posts from last x years

<?php $today = getdate(); $args = array( //’nopaging’ => true, ‘paged’ => $paged, ‘category’ => 1, ‘posts_per_page’ => 36, ‘date_query’ => array( array( ‘after’ => $today[ ‘month’ ] . ‘ 1st, ‘ . ($today[ ‘year’ ] – 2) ) ) ); $catgory_posts = new WP_Query( $args ); // The Query ?> <div id=”grid”> <?php if( … Read more