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.