Title: Custom Post Looping
Last modified: August 22, 2016

---

# Custom Post Looping

 *  Resolved [Niko](https://wordpress.org/support/users/nikosites/)
 * (@nikosites)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/custom-post-looping/)
 * Hi!
    I was looking for the way how to display the posts by Years (like for 2011,
   2012, 21013) separately on pages created for that content. I found a few plugins,
   but they are not what I’d like to do spliting the posts just for the exact year
   by page. Where (which page(es)) can I figure that kind of Query to display in
   loop later? Thanks

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * (@wpmudev-support2)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/custom-post-looping/#post-5565713)
 * Hello nikosites,
 * You can add this before [The Loop](http://codex.wordpress.org/The_Loop).
 *     ```
       <?php
         function filter_where($where = '') {
           //specific date range for year 2011
           $where .= " AND post_date > '" . date('Y-m-d', strtotime('2011-01-01')) . "'";
           $where .= " AND post_date < '" . date('Y-m-d', strtotime('2011-12-31')) . "'";
           return $where;
         }
       add_filter('posts_where', 'filter_where');
       query_posts($query_string);
   
       ?>
       ```
   
 * Then after the loop put this code:
 *     ```
       <?php remove_filter('posts_where', 'filter_where'); ?>
       ```
   
 * to avoid problem on another loop.
 * Look for php’s [strtotime](http://php.net/manual/en/function.strtotime.php) for
   other valid parameter. 🙂
 * Let me know if that helps.
 * Best Regards,
    Calvin
 *  Thread Starter [Niko](https://wordpress.org/support/users/nikosites/)
 * (@nikosites)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/custom-post-looping/#post-5565870)
 * Thanks Kalvin
    I could not finde the exact place, where to place the code… I 
   tried it on loop.php and loop-page.php of my active theme, but….
 * I’d like to know which page needs to take that code. I use to work with wordpress
   and modify it, but not the PHP part. (I know PHP, but not a core professional
   🙂
 * I tried to find where the created (by user) pages reside, but it does not work
   like this – I think. they must be dynamic.
 * I created four pages (2011 to 2014) to archive and close the posts of these years
   and display them on these 4 pages separately by year, but could not resolve that
   task till not.
    That’s because I posted to find the tips. thanks…
 *  [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * (@wpmudev-support2)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/custom-post-looping/#post-5565890)
 * Hello nikosites,
 * What theme are you currently using? You can create a template page for each year
   but that is not the best way to go. I also suggest you learn how metabox works.
   [http://codex.wordpress.org/Function_Reference/add_meta_box](http://codex.wordpress.org/Function_Reference/add_meta_box)
 * Using metabox, you can just insert year then it will dynamically query depends
   on the year your input.
 * Best Regards,
    Calvin
 *  Thread Starter [Niko](https://wordpress.org/support/users/nikosites/)
 * (@nikosites)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/custom-post-looping/#post-5565893)
 * Hi Calvin
    Thanks for trying to help. My actual theme is “purple pastels”.
 * I will check and learn about metabox and post back here the result.
    thank you…
 *  Thread Starter [Niko](https://wordpress.org/support/users/nikosites/)
 * (@nikosites)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/custom-post-looping/#post-5565912)
 * Thanks Calvin.
    I found different solution, because the way I wanted to do, it
   could take a lot of time and work digging inside de code. I could not find the
   plugin for this (maybe in future someone will create the plugin) I have just 
   created a new page for the next year posts, closed the posts for the actual 2014
   page and placed it under the “archived posts” page as sub menu.
 * Case resolved.
    Merry christmas…
 *  [santhoshk](https://wordpress.org/support/users/santhoshk/)
 * (@santhoshk)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/custom-post-looping/#post-5565925)
 * Hi
    I am using wordpress realto theme & bottom of the page there is 3 slider,
   for that slider i made 3 category for property show that is pre-lunch property,
   Under construction & ready to move, so in that slider all slide move at time 
   but how can i make it each slide will slide itself.
 * Finally need all property will show different slide, it means 1st slide pre-launch.
   2nd slide under construction, 3rd page ready to move. this will show all different
   page slide if upload randomly

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Custom Post Looping’ is closed to new replies.

## Tags

 * [custom loop](https://wordpress.org/support/topic-tag/custom-loop/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 6 replies
 * 3 participants
 * Last reply from: [santhoshk](https://wordpress.org/support/users/santhoshk/)
 * Last activity: [11 years, 5 months ago](https://wordpress.org/support/topic/custom-post-looping/#post-5565925)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
