Conditions | 7 |
Paths | 9 |
Total Lines | 68 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | function advanced_custom_search($where, &$wp_query) |
||
24 | { |
||
25 | global $wpdb; |
||
26 | |||
27 | if (empty($where)) { |
||
28 | return $where; |
||
29 | } |
||
30 | |||
31 | // get search expression |
||
32 | $terms = $wp_query->query_vars['s']; |
||
33 | |||
34 | // explode search expression to get search terms |
||
35 | $exploded = explode(' ', $terms); |
||
36 | |||
37 | if ($exploded === false || count($exploded) == 0) { |
||
38 | $exploded = array(0 => $terms); |
||
39 | } |
||
40 | |||
41 | // reset search in order to rebuilt it as we whish |
||
42 | $where = ''; |
||
43 | |||
44 | // get searcheable_acf, a list of advanced custom fields you want to search content in |
||
45 | $list_searcheable_acf = list_searcheable_acf(); |
||
46 | |||
47 | foreach ($exploded as $tag) { |
||
48 | $where .= " |
||
49 | AND ( |
||
50 | (wp_posts.post_title LIKE '%$tag%') |
||
51 | OR (wp_posts.post_content LIKE '%$tag%') |
||
52 | OR EXISTS ( |
||
53 | SELECT * FROM wp_postmeta |
||
54 | WHERE post_id = wp_posts.ID |
||
55 | AND ("; |
||
56 | |||
57 | foreach ($list_searcheable_acf as $searcheable_acf) { |
||
58 | if ($searcheable_acf == $list_searcheable_acf[0]) { |
||
59 | $where .= " (meta_key LIKE '%" . $searcheable_acf . "%' AND meta_value LIKE '%$tag%') "; |
||
60 | } else { |
||
61 | $where .= " OR (meta_key LIKE '%" . $searcheable_acf . "%' AND meta_value LIKE '%$tag%') "; |
||
62 | } |
||
63 | |||
64 | $where .= ") |
||
65 | ) |
||
66 | OR EXISTS ( |
||
67 | SELECT * FROM wp_comments |
||
68 | WHERE comment_post_ID = wp_posts.ID |
||
69 | AND comment_content LIKE '%$tag%' |
||
70 | ) |
||
71 | OR EXISTS ( |
||
72 | SELECT * FROM wp_terms |
||
73 | INNER JOIN wp_term_taxonomy |
||
74 | ON wp_term_taxonomy.term_id = wp_terms.term_id |
||
75 | INNER JOIN wp_term_relationships |
||
76 | ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id |
||
77 | WHERE ( |
||
78 | taxonomy = 'post_tag' |
||
79 | OR taxonomy = 'category' |
||
80 | OR taxonomy = 'myCustomTax' |
||
81 | ) |
||
82 | AND object_id = wp_posts.ID |
||
83 | AND wp_terms.name LIKE '%$tag%' |
||
84 | ) |
||
85 | )"; |
||
86 | } |
||
87 | |||
88 | return $where; |
||
89 | } |
||
90 | } |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.