This repository has been archived by the owner on Mar 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Results.php
73 lines (66 loc) · 1.54 KB
/
Results.php
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Class BPFResults
* Search engine
*/
class BPFResults
{
/**
* @var array Searchable fields
*/
private $fields = array();
/**
* @var null|object The $wp_query object
*/
private $query = null;
/**
* @param array $fields
*/
public function __construct($fields = array())
{
$this->fields = $fields;
}
/**
* Performs the search and stores the results in the main loop
*/
public function search()
{
$args = array(
'suppress_filters' => true
);
/**
* Prepare the meta query
*/
$meta_query = array();
foreach ($this->fields as $field => $values) {
if (isset($_GET[BPFUtils::slugify($field)]) && in_array($_GET[BPFUtils::slugify($field)], $values)) {
$meta_query[] = array(
'key' => $field,
'value' => $_GET[BPFUtils::slugify($field)],
'compare' => '=',
);
}
}
/**
* Not a valid search
*/
if (count($meta_query) == 0) {
return;
}
$args['meta_query'] = $meta_query;
/**
* Performs the actual search and stores the results in the main loop
*/
query_posts($args);
global $wp_query;
$this->query = $wp_query;
}
/**
* Returns the $wp_query object
* @return null|object
*/
public function get_query()
{
return $this->query;
}
}