forked from WordPress/WordPress-Coding-Standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlowDBQueryStandard.xml
More file actions
33 lines (30 loc) · 1.08 KB
/
SlowDBQueryStandard.xml
File metadata and controls
33 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?xml version="1.0"?>
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
title="Slow DB Query"
>
<standard>
<![CDATA[
Usage of the meta_query, meta_key, meta_value, and tax_query keys in array assignments and query-parameter strings is discouraged and should be carefully evaluated. When passed to WordPress database query APIs, these keys can lead to slow queries, especially on large datasets.
]]>
</standard>
<code_comparison>
<code title="Valid: No potentially slow query keys.">
<![CDATA[
$query = new WP_Query( array(
'post_type' => 'post',
) );
$args = 'post_type=post&orderby=date';
]]>
</code>
<code title="Invalid: Using potentially slow query keys.">
<![CDATA[
$query = new WP_Query( array(
'<em>meta_key</em>' => 'color',
'<em>meta_value</em>' => 'blue',
) );
$args = 'post_type=post&<em>meta_key</em>=featured';
]]>
</code>
</code_comparison>
</documentation>