• Hello,

    The codes of my home page are like following,

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="post" id="post-<?php the_ID(); ?>">
          <div class="posttop">
              <img src="/images/get-ringtone.gif" alt="ringtones">
            <h1 class="posttitle"><a href="<?php the_permalink() ?>" rel="bookmark">
              <?php the_title(); ?>
              </a></h1>
    
            <div class="clear" style="margin-bottom:15px;"></div>
            <div class="storycontent">
              <?php the_content(__('more...')); ?>
    
              <?php } ?>

    When visiting homepage, the following SQL are executed,
    SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 10

    I have 100k articles in WordPress, so it’s quite slow to ‘ORDER BY wp_posts.post_date’.
    Is there any method to ORDER BY ID?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello bryanwang,

    welcome to the wordpress support forums.

    At first read i would suggest to add an index over wp_posts.post_date. Which version of wordpress are you using?

    To order by ID, create a plugin using the following

    add_filter('posts_orderby', 'jt_search_orderby' );
    
    function jt_search_orderby($orderby)
    {
    	if( is_page('all') || is_search() || is_category() ) {
    
            return "ID ASC";
      }
    
      return $orderby;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Posts on homepage order by ID?’ is closed to new replies.