Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

 

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
New Webmasters ask "How-To" questions here. This is where other fucking Webmasters help.

 
Thread Tools
Old 11-10-2012, 08:43 AM   #1
LucyVanAngel
Confirmed User
 
Join Date: Mar 2009
Posts: 305
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
LucyVanAngel is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
Old 11-10-2012, 12:54 PM   #2
HostedinVegas
Confirmed User
 
Industry Role:
Join Date: Feb 2011
Posts: 108
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
HostedinVegas is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
Old 11-11-2012, 02:54 PM   #3
senortriangulo
Registered User
 
Industry Role:
Join Date: Oct 2012
Posts: 53
Quote:
Originally Posted by LucyVanAngel View Post
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 at 02:55 PM..
senortriangulo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
Old 11-11-2012, 04:41 PM   #4
Miguel T
♦ Web Developer ♦
 
Miguel T's Avatar
 
Industry Role:
Join Date: May 2005
Location: Full-Stack Developer
Posts: 12,468
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
Miguel T is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
Old 11-12-2012, 10:01 PM   #5
fusionx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Olongapo City, Philippines
Posts: 4,618
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.
fusionx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook
 
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.