|
5 | 5 | > |
6 | 6 | <standard> |
7 | 7 | <![CDATA[ |
8 | | - For performance reason, it's recommended to avoid doing lots of meta queries. |
9 | | - The underlying SQL request generated by those queries can be extremely slow queries especially for complexe meta query. |
| 8 | + 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. |
10 | 9 | ]]> |
11 | 10 | </standard> |
12 | 11 | <code_comparison> |
13 | | - <code title="Valid: Using tax_query to retrieve a list of posts"> |
| 12 | + <code title="Valid: No potentially slow query keys."> |
14 | 13 | <![CDATA[ |
15 | | -$query = new WP_Query( |
16 | | - array( |
17 | | - 'tax_query' => array( |
18 | | - array( |
19 | | - 'taxonomy' => 'color', |
20 | | - 'field' => 'slug', |
21 | | - 'terms' => array( |
22 | | - 'blue', |
23 | | - 'red', |
24 | | - ) |
25 | | - ) |
26 | | - ) |
27 | | - ) |
| 14 | +$args = array( |
| 15 | + 'post_type' => 'post', |
28 | 16 | ); |
29 | | - ]]> |
30 | | - </code> |
31 | | - <code title="Invalid: Using meta_query to retrieve a list of posts"> |
32 | | - <![CDATA[ |
33 | | -$query = new WP_Query( |
34 | | - array( |
35 | | - 'meta_query' => array( |
36 | | - array( |
37 | | - 'key' => 'color', |
38 | | - 'compare' => 'IN', |
39 | | - 'value' => array( |
40 | | - 'blue', |
41 | | - 'red', |
42 | | - ) |
43 | | - ) |
44 | | - ) |
45 | | - ) |
46 | | -); |
47 | | - ]]> |
48 | | - </code> |
49 | | - </code_comparison> |
50 | | - <code_comparison> |
51 | | - <code title="Valid: in case of binary metadata (true/false) check if meta_key exist and remove it otherwise"> |
52 | | - <![CDATA[ |
53 | | -// mark post 123 as "featured" |
54 | | -update_post_meta( 123, 'is_featured', true ); |
55 | 17 |
|
56 | | -// remove "featured" state for post 456 |
57 | | -delete_post_meta( 456, 'is_featured' ); |
58 | 18 |
|
59 | | -$query = new WP_Query( |
60 | | - array( |
61 | | - 'meta_key' => 'is_featured' |
62 | | - ), |
63 | | -); |
| 19 | +$query = 'post_type=post&orderby=date'; |
64 | 20 | ]]> |
65 | 21 | </code> |
66 | | - <code title="Invalid: check for the value of a binary metadata, which is slower"> |
| 22 | + <code title="Invalid: Using potentially slow query keys."> |
67 | 23 | <![CDATA[ |
68 | | -// mark post 123 as "featured" |
69 | | -update_post_meta( 123, 'is_featured', true ); |
70 | | -
|
71 | | -// mark post 456 as not "featured" |
72 | | -update_post_meta( 456, 'is_featured', false ); |
73 | | -
|
74 | | -$query = new WP_Query( |
75 | | - array( |
76 | | - 'meta_key' => 'is_featured', |
77 | | - 'meta_value' => true |
78 | | - ), |
| 24 | +$args = array( |
| 25 | + '<em>meta_key</em>' => 'color', |
| 26 | + '<em>meta_value</em>' => 'blue', |
79 | 27 | ); |
| 28 | +
|
| 29 | +$query = 'post_type=post&<em>meta_key</em>=featured'; |
80 | 30 | ]]> |
81 | 31 | </code> |
82 | 32 | </code_comparison> |
|
0 commit comments