wordpress - php question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LucyVanAngel
    Confirmed User
    • Mar 2009
    • 327

    #1

    wordpress - php question

    hi, one of my blogs is running too slow because of the amount of posts (over 5000)
    the index.php file of wp has the following code:

    #########
    <?php if(have_posts()) { ?>
    <?php while (have_posts()) : the_post(); ?>
    #########

    The have_posts() function is defined as follows:
    ############
    ./wp-includes/query.php: function have_posts() {
    if ( $this->current_post + 1 < $this->post_count ) {
    return true;
    } elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0 ) {
    do_action_ref_array('loop_end', array(&$this));
    // Do some cleaning up after the loop
    $this->rewind_posts();
    }

    $this->in_the_loop = false;
    return false;
    }
    #####################

    Wordpress is returning EVERY single post (5000) in the database and then iterating over them performing a SQL query for each.
    It does not help changing the theme because that routine is in wp itself not in the theme.

    Anybody help ?

    thanks
  • HostedinVegas
    Confirmed User
    • Feb 2011
    • 110

    #2
    Your best bet is to limit the mysql_query, save beating the server. There are several ways to do this, check out http://www.phpsimplicity.com/tips.php?id=1 for some great howto's

    Thanks,
    Anthony
    Now Part of the Your Hosting Solutions / Hosting for a Dollar Network.Affordable Hosting Solutions
    Shared Hosting, VPS, Dedicated Servers, and More !!

    Comment

    • senortriangulo
      Registered User
      • Oct 2012
      • 53

      #3
      Originally posted by LucyVanAngel
      hi, one of my blogs is running too slow because of the amount of posts (over 5000)
      the index.php file of wp has the following code:

      #########
      <?php if(have_posts()) { ?>
      <?php while (have_posts()) : the_post(); ?>
      #########

      The have_posts() function is defined as follows:
      ############
      ./wp-includes/query.php: function have_posts() {
      if ( $this->current_post + 1 < $this->post_count ) {
      return true;
      } elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0 ) {
      do_action_ref_array('loop_end', array(&$this));
      // Do some cleaning up after the loop
      $this->rewind_posts();
      }

      $this->in_the_loop = false;
      return false;
      }
      #####################

      Wordpress is returning EVERY single post (5000) in the database and then iterating over them performing a SQL query for each.
      It does not help changing the theme because that routine is in wp itself not in the theme.

      Anybody help ?

      thanks
      There's gotta be a way to configure this without messing with the PHP code right?

      I don't really know much about Wordpress or what the_post() is doing, but if worst comes to worst, you could always add a function to query.php that sets current_post to a few hundred less than the number of posts.


      function jump_post($index)
      {
      $this->current_post=$index;
      }
      Last edited by senortriangulo; 11-11-2012, 12:55 PM.

      Comment

      • Miguel T
        ♦ Web Developer ♦
        • May 2005
        • 12473

        #4
        Try to re-code the loop with WP_Query() , but limiting the results posted.
        THat should fix the slowness you describe...

        Full Stack Webdeveloper: HTML5/CSS3, jQuery, AJAX, ElevatedX, NATS, MechBunny, Wordpress

        Comment

        • fusionx
          Confirmed User
          • Nov 2003
          • 4618

          #5
          I'm 99% certain it's only looping over the number of posts defined to show on the home page.

          From the codex:

          $post_count
          The number of posts being displayed.

          Not the total number of posts in your DB.

          Comment

          Working...