How to optimize query_posts get WordPress articles, reduce the number of database queries?

Source: Internet
Author: User
Tags php foreach
How to optimize the following WordPress code, currently it is a separate query, resulting in a large number of database queries, in fact, is to achieve a one-time access to data, the cyclic output classification name, classification of article number.


  
             
  
   $value){ ?>             
  
                 

">

  • " rel="bookmark" title=" ">

Reply content:

How to optimize the following WordPress code, currently it is a separate query, resulting in a large number of database queries, in fact, is to achieve a one-time access to data, the cyclic output classification name, classification of article number.


  
             
  
   $value){ ?>             
  
                 

">

  • " rel="bookmark" title=" ">

Do you open the cache and solve it?

1. Now the problem is too many categories, each classification to query once, that can be found in the page classification of all the data, because it is a query all and you have a sort and article number requirements, here can be combined with group by to obtain the request data. (So the first page of categorical data this should be only one query)

2. Then, in accordance with the code logic to form an array, the array can refer to the format I gave you below.

$postList[cate_id]['title'];$postList[cate_id]['article'][];//将文章按分类id当成键值存入数组foreach($postList as $post) {    foreach($post['article'] as $value){            

Oneself top down, look forward to have a familiar with WP's small partners to see.

Not familiar with WP also how to look at your code. You can use a key-value pair like that, just write a loop.
Check all the classifications to make up the key value array first.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.