[resolved] Is this code for related posts slowing down my site? (6 posts)

  1. kk4uga
    Posted 4 years ago #

    Hello, I have the following code on pages of my site. The code shows a list of related posts by TAG.

    My site, which is on a fast dedicated server, gets very busy on certain days and goes unresponsive. I'm wondering if this code is querying the database too much.

    Can someone look at it and see if it looks ok? Thx.

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. kk4uga
    Posted 4 years ago #

    Here is the link to the code:


  3. kk4uga
    Posted 4 years ago #

    The reason I am asking is because of this from the WordPress codex:

    If you use query_posts within a template page, WordPress will have already executed the database query and retrieved the records by the time it gets to your template page (that's how it knew which template page to serve up!). So when you over-ride the default query with query_posts(), you're essentially throwing away the default query and its results and re-executing another query against the database.

    This is not necessarily a problem, especially if you're dealing with a smaller blog-based site. Developers of large sites with big databases and heavy visitor traffic may wish to consider alternatives, such as modifying the default request directly (before it's called). The request filter can be used to achieve exactly this.

    The 'parse_query' and the 'pre_get_posts' filters are also available to modify the internal $query object that is used to generate the SQL to query the database.

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    I don't see anything in that code that would place a significant strain on the database.

  5. kk4uga
    Posted 4 years ago #

    Thanks. Would limiting the number of posts to "get" improve performance? Right now it's unlimited, but at most it would pull 30-40 posts.

  6. egoipse
    Posted 3 years ago #

    You commanded to wordpress to include 200 terms in your calling. At least the performance of your site will get poorer...

Topic Closed

This topic has been closed to new replies.

About this Topic