• Hi,

    I’m working on a project with WordPress 2.5. After we set up all of the pages, I viewed the source and noticed that there were a little over 90 queries being executed on the page. I found out the the culprit was the sidebar – when I removed it about 80 queries went away. I did a bit more research and it seems like these queries were coming from the get_permalink() function. This function was using 2 queries per call. 1 for &get_posts() and another because we had %category% in the permalink structure. For optimization, I removed %category% from the permalink structure.

    The sidebar has been removed from the site ( we don’t really want it ), but get_permalink() is needed elsewhere on the site and seems to increase the query count where not necessary… like in The Loop: You feed get_permalink() the ID of the post for which you want to display a permalink for and it uses &get_posts() to query the database, If I had twenty links out to posts on my homepage (which I do) this will add 20 queries to the Homepage for no reason as $post is already defined and has already been queried for.

    It makes sense to me that this function should be able to take either an integer (representing ID) or and object representing the entire post and figure out whether to query based of the type of variable passed.

    Don’t really know if this was the right place to post this, but thought I would get it out there, because I did a bunch of testing on it this morning.

    If anyone knows of any optimized function libraries or written resources that help to cut down on query count, please post.

    Thanks,
    -Mike

  • The topic ‘Optimiztion Resources – Sql – Too Many WordPress Queries’ is closed to new replies.