WordPress.org

Ready to get started?Download WordPress

Forums

Quark
[resolved] Posts Ascending Order (4 posts)

  1. mbadawi23
    Member
    Posted 1 year ago #

    Hello again,

    I have a quick question. I'm trying to show my posts in ascending order so older posts are shown first on my posts page. I found comments online to add query_posts($query_string . "&order=ASC"); before the posts loop. So where is the posts loop located?

    Thanks a lot.

  2. ahortin
    Member
    Theme Author

    Posted 1 year ago #

    The correct way to change your query is using pre_get_posts. To reverse the order the blog posts are displayed, you can add this to your functions.php file.

    function my_pre_get_posts( $query ) {
       global $wp;
       if ( !is_admin() && is_home() && $query->is_main_query() ) {
          $query->set( 'order', 'ASC' );
          return;
       }
    }
    add_action( 'pre_get_posts', 'my_pre_get_posts' );
  3. mbadawi23
    Member
    Posted 1 year ago #

    Thanks a lot.. that worked as a charm.

  4. ahortin
    Member
    Theme Author

    Posted 1 year ago #

    You're welcome. Glad it solved your problem.

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic

Tags