0

I have created a page called Blog and selected it as posts page. What I need here is, I don't want to show all posts but I need to show only posts from 2015 to till date.

How can I achieve this?

  • 1
    What did you try so far? Please post your current relevant code. – birgire Apr 4 '17 at 9:50
  • It's been a while since I've done this, but review query_posts() and WP_Query. You should be able to set date/time requirements before you call your post loop. – Greg McMullen Apr 4 '17 at 13:31
0

You should adapt it to fit your needs, e.g. (not tested) :
// Create a new filtering function that will add our where clause to the query

function filter_where( $where = '' ) {
   $where .= " AND post_date > '" . date('Y-m-d', strtotime('-1 year')) . "'";
return $where;
}<br>

add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );<br>
remove_filter( 'posts_where', 'filter_where' );
|improve this answer|||||
  • Why not use the date_query argument in WP_Query ? – birgire Apr 4 '17 at 12:47
  • Yes you can use data_query arguments with different params acc. to your need codex – Akhilesh29989 Apr 5 '17 at 5:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.