Title: Chronological Posts with PHP &amp; Not a Plugin
Last modified: August 15, 2017

---

# Chronological Posts with PHP & Not a Plugin

 *  Resolved [ElasticMind](https://wordpress.org/support/users/elasticmind/)
 * (@elasticmind)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/)
 * Hello,
 * I’m curious, does anyone know how I can make my blog posts appear in chronological
   order without using a plugin but rather PHP? Currently, I’m using the plugin 
   Chronological Posts to get the effect I need but I’m finding that it freezes/
   disables the updating of my RSS feed as a result.
 * The site I’m creating this effect on my site.
    As you can see from the feed /
   feed, all new posts have not appeared there and I have determined it’s due to
   the plugin.
 * Any help you can provide is much appreciated,
 * Tara
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fchronological-posts-with-php-not-a-plugin%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9412393)
 * Posts should appear in descending chronological order. No plugin should be needed
   for that.
 *  Thread Starter [ElasticMind](https://wordpress.org/support/users/elasticmind/)
 * (@elasticmind)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9412406)
 * Sorry Steve, I should have been more clear. I need them to be ascending order.
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9412456)
 * Use a callback function for pre_get_posts to change the sort order from DESC 
   to ASC. That will change them from newest first to oldest first.
 * [https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts)
 *  Thread Starter [ElasticMind](https://wordpress.org/support/users/elasticmind/)
 * (@elasticmind)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9415852)
 * Thanks for getting back to me, Steve. I’m not exactly clear on what I need to
   do… would you be able to be more specific about the PHP code needed?
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9415864)
 * This is NOT tested code — you need to do SOMETHING LIKE this….
 *     ```
       add_action( 'pre_get_posts', 'reverse_post_order' );
       function reverse_post_order( $query ) {
          if ( is_main_query() && is_archive() ) {  // this is the conditional you have to work on
             $query->set( 'order', 'ASC');
              }
       }
       ```
   
 * see [https://codex.wordpress.org/Conditional_Tags](https://codex.wordpress.org/Conditional_Tags)
    -  This reply was modified 9 years, 1 month ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
 *  Thread Starter [ElasticMind](https://wordpress.org/support/users/elasticmind/)
 * (@elasticmind)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9418907)
 * Thank you so much, Steve. I’m sorry to take up more of your time but I’ve tested
   this code and I’m still not getting the results I’m looking for… this code is
   placed in my child theme’s function.php file:
 * /*===================================================================*/
    /* 4.
   CHRONOLOGICAL ORDER /*=======================================================
   ============*/ add_action( ‘pre_get_posts’, ‘reverse_post_order’ ); function 
   reverse_post_order( $query ) { if ( is_main_query() && is_front_page() && is_home()){
   $query->set( ‘order’, ‘ASC’); } }
 * I don’t need the archive to be in chronological order, so I removed that condition
   and added that I need the homepage/blog page in chronological order. Using that
   code, it’s still in descending order. Any idea why it’s not working?
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9418945)
 * Because that makes no sense. What order do you want the posts to be in?
 * How is your home page content set?
    -  This reply was modified 9 years, 1 month ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
 *  Thread Starter [ElasticMind](https://wordpress.org/support/users/elasticmind/)
 * (@elasticmind)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9418976)
 * Thanks again for your help, Steve. I’m going to pause on this until tomorrow 
   as the “Chronological Posts” plugin author has provided me with a solution to
   fix the RSS feed issue that I’m hoping will work and I won’t need to fiddle with
   this code. I’ll be in touch tomorrow and if all works I’ll mark this discussion
   as resolved. Thanks again for your support so far.
 *  Thread Starter [ElasticMind](https://wordpress.org/support/users/elasticmind/)
 * (@elasticmind)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9422577)
 * The “Chronological Posts” plugin author has provided me with a solution to fix
   the RSS feed issue and so I’ve marked this discussion as resolved. Thanks again
   for your time and help, Steve.

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

 The topic ‘Chronological Posts with PHP & Not a Plugin’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 2 participants
 * Last reply from: [ElasticMind](https://wordpress.org/support/users/elasticmind/)
 * Last activity: [9 years, 1 month ago](https://wordpress.org/support/topic/chronological-posts-with-php-not-a-plugin/#post-9422577)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
