GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 377ed0...81a8a0 )
by Vincent
03:08
created

advancedCustomSearch.php ➔ list_searcheable_acf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * [list_searcheable_acf list all the custom fields we want to include in our search query]
5
 * @return [array] [list of custom fields]
0 ignored issues
show
Documentation introduced by
The doc-type [array] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

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.

Loading history...
6
 */
7
function list_searcheable_acf()
8
{
9
    $list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
10
11
    return $list_searcheable_acf;
12
}
13
14
/**
15
 * [advanced_custom_search search that encompasses ACF/advanced custom fields and taxonomies and split expression
16
 * before request]
17
 * @param  [query-part/string]      $where    [the initial "where" part of the search query]
0 ignored issues
show
Documentation introduced by
The doc-type [query-part/string] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

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.

Loading history...
18
 * @param  [object]                 $wp_query []
0 ignored issues
show
Documentation introduced by
The doc-type [object] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

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.

Loading history...
19
 * @return [query-part/string]      $where    [the "where" part of the search query as we customized]
0 ignored issues
show
Documentation introduced by
The doc-type [query-part/string] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

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.

Loading history...
20
 * see https://vzurczak.wordpress.com/2013/06/15/extend-the-default-wordpress-search/
21
 * credits to Vincent Zurczak for the base query structure/spliting tags section
22
 */
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
}