Version Description
- Fixed a PHP error when setting defaults for taxonomies - many users did not see this but resulted in unexpected behaviour
- Fixed an error with post date sometimes being undefined for blank searches
- Added argument
empty_search_url
- when a users submits the search form without any search preferences selected they will be redirected to this URL - Updated argument
add_search_param
- setting to1
will force add a "?s=" to all urls generate by the plugin - this may help with the loading of search templates in some themes
Download this release
Release Info
Developer | DesignsAndCode |
Plugin | Search & Filter |
Version | 1.2.5 |
Comparing to | |
See all releases |
Code changes from version 1.2.4 to 1.2.5
- of-taxonomy-walker.php +318 -318
- readme.txt +34 -9
- search-filter.php +1723 -1689
of-taxonomy-walker.php
CHANGED
@@ -1,319 +1,319 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Taxonomy_Walker extends Walker_Category {
|
4 |
-
|
5 |
-
|
6 |
-
private $type = '';
|
7 |
-
private $defaults = array();
|
8 |
-
private $multidepth = 0; //manually calculate depth on multiselects
|
9 |
-
private $multilastid = 0; //manually calculate depth on multiselects
|
10 |
-
private $multilastdepthchange = 0; //manually calculate depth on multiselects
|
11 |
-
|
12 |
-
function __construct($type = 'checkbox', $defaults = array()) {
|
13 |
-
// fetch the list of term ids for the given post
|
14 |
-
//$this->term_ids = wp_get_post_terms( $post_id, $taxonomy, 'fields=ids' );
|
15 |
-
//var_dump($this->term_ids);
|
16 |
-
|
17 |
-
$this->type = $type;
|
18 |
-
$this->defaults = $defaults;
|
19 |
-
}
|
20 |
-
|
21 |
-
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
|
22 |
-
/*$display = false;
|
23 |
-
|
24 |
-
$id = $element->term_id;
|
25 |
-
|
26 |
-
$display = true;
|
27 |
-
if ( isset( $children_elements[ $id ] ) ) {
|
28 |
-
// the current term has children
|
29 |
-
foreach ( $children_elements[ $id ] as $child ) {
|
30 |
-
if ( in_array( $child->term_id, $this->term_ids ) ) {
|
31 |
-
// one of the term's children is in the list
|
32 |
-
$display = true;
|
33 |
-
// can stop searching now
|
34 |
-
break;
|
35 |
-
}
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
-
if ( $display )*/
|
40 |
-
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
|
41 |
-
}
|
42 |
-
|
43 |
-
|
44 |
-
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 )
|
45 |
-
{
|
46 |
-
|
47 |
-
if($this->type=="list")
|
48 |
-
{
|
49 |
-
extract($args);
|
50 |
-
|
51 |
-
$cat_name = esc_attr( $category->name );
|
52 |
-
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
53 |
-
$link = '<a href="' . esc_url( get_term_link($category) ) . '" ';
|
54 |
-
if ( $use_desc_for_title == 0 || empty($category->description) )
|
55 |
-
$link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
|
56 |
-
else
|
57 |
-
$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
|
58 |
-
$link .= '>';
|
59 |
-
$link .= $cat_name . '</a>';
|
60 |
-
|
61 |
-
if ( !empty($feed_image) || !empty($feed) ) {
|
62 |
-
$link .= ' ';
|
63 |
-
|
64 |
-
if ( empty($feed_image) )
|
65 |
-
$link .= '(';
|
66 |
-
|
67 |
-
$link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) ) . '"';
|
68 |
-
|
69 |
-
if ( empty($feed) ) {
|
70 |
-
$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
|
71 |
-
} else {
|
72 |
-
$title = ' title="' . $feed . '"';
|
73 |
-
$alt = ' alt="' . $feed . '"';
|
74 |
-
$name = $feed;
|
75 |
-
$link .= $title;
|
76 |
-
}
|
77 |
-
|
78 |
-
$link .= '>';
|
79 |
-
|
80 |
-
if ( empty($feed_image) )
|
81 |
-
$link .= $name;
|
82 |
-
else
|
83 |
-
$link .= "<img src='$feed_image'$alt$title" . ' />';
|
84 |
-
|
85 |
-
$link .= '</a>';
|
86 |
-
|
87 |
-
if ( empty($feed_image) )
|
88 |
-
$link .= ')';
|
89 |
-
}
|
90 |
-
|
91 |
-
if ( !empty($show_count) )
|
92 |
-
$link .= ' (' . intval($category->count) . ')';
|
93 |
-
|
94 |
-
if ( 'list' == $args['style'] ) {
|
95 |
-
$output .= "\t<li";
|
96 |
-
$class = 'cat-item cat-item-' . $category->term_id;
|
97 |
-
if ( !empty($current_category) ) {
|
98 |
-
$_current_category = get_term( $current_category, $category->taxonomy );
|
99 |
-
if ( $category->term_id == $current_category )
|
100 |
-
$class .= ' current-cat';
|
101 |
-
elseif ( $category->term_id == $_current_category->parent )
|
102 |
-
$class .= ' current-cat-parent';
|
103 |
-
}
|
104 |
-
$output .= ' class="' . $class . '"';
|
105 |
-
$output .= ">$link\n";
|
106 |
-
} else {
|
107 |
-
$output .= "\t$link<br />\n";
|
108 |
-
}
|
109 |
-
}
|
110 |
-
else if(($this->type=="checkbox")||($this->type=="radio"))
|
111 |
-
{
|
112 |
-
extract($args);
|
113 |
-
|
114 |
-
$cat_name = esc_attr( $category->name );
|
115 |
-
$cat_id = esc_attr( $category->term_id );
|
116 |
-
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
117 |
-
|
118 |
-
//check a default has been set
|
119 |
-
$checked = "";
|
120 |
-
if($defaults)
|
121 |
-
{
|
122 |
-
$noselected = count($this->defaults);
|
123 |
-
|
124 |
-
if(($noselected>0)&&(is_array($defaults)))
|
125 |
-
{
|
126 |
-
foreach($defaults as $defaultid)
|
127 |
-
{
|
128 |
-
if($defaultid==$cat_id)
|
129 |
-
{
|
130 |
-
$checked = ' checked="checked"';
|
131 |
-
}
|
132 |
-
}
|
133 |
-
}
|
134 |
-
}
|
135 |
-
|
136 |
-
$link = "<label><input type='".$this->type."' name='".$name."[]' value='".$cat_id."'".$checked." /> ".$cat_name;
|
137 |
-
|
138 |
-
|
139 |
-
if ( !empty($show_count) )
|
140 |
-
$link .= ' (' . intval($category->count) . ')';
|
141 |
-
|
142 |
-
|
143 |
-
$link .= "</label>";
|
144 |
-
|
145 |
-
if ( 'list' == $args['style'] ) {
|
146 |
-
$output .= "\t<li";
|
147 |
-
$class = 'cat-item cat-item-' . $category->term_id;
|
148 |
-
if ( !empty($current_category) ) {
|
149 |
-
$_current_category = get_term( $current_category, $category->taxonomy );
|
150 |
-
if ( $category->term_id == $current_category )
|
151 |
-
$class .= ' current-cat';
|
152 |
-
elseif ( $category->term_id == $_current_category->parent )
|
153 |
-
$class .= ' current-cat-parent';
|
154 |
-
}
|
155 |
-
$output .= ' class="' . $class . '"';
|
156 |
-
$output .= ">$link\n";
|
157 |
-
} else {
|
158 |
-
$output .= "\t$link<br />\n";
|
159 |
-
}
|
160 |
-
}
|
161 |
-
else if($this->type=="multiselect")
|
162 |
-
{
|
163 |
-
extract($args);
|
164 |
-
|
165 |
-
$cat_name = esc_attr( $category->name );
|
166 |
-
$cat_id = esc_attr( $category->term_id );
|
167 |
-
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
168 |
-
|
169 |
-
//check a default has been set
|
170 |
-
$checked = "";
|
171 |
-
if($defaults)
|
172 |
-
{
|
173 |
-
$noselected = count($this->defaults);
|
174 |
-
|
175 |
-
if(($noselected>0)&&(is_array($defaults)))
|
176 |
-
{
|
177 |
-
foreach($defaults as $defaultid)
|
178 |
-
{
|
179 |
-
if($defaultid==$cat_id)
|
180 |
-
{
|
181 |
-
$checked = ' selected="selected"';
|
182 |
-
}
|
183 |
-
}
|
184 |
-
}
|
185 |
-
}
|
186 |
-
|
187 |
-
|
188 |
-
/* Custom depth calculations! :/ */
|
189 |
-
if($category->parent == 0)
|
190 |
-
{//then this has no parent so reset depth
|
191 |
-
$this->multidepth = 0;
|
192 |
-
}
|
193 |
-
else if($category->parent == $this->multilastid)
|
194 |
-
{
|
195 |
-
$this->multidepth++;
|
196 |
-
$this->multilastdepthchange = $this->multilastid;
|
197 |
-
}
|
198 |
-
else if($category->parent == $this->multilastdepthchange)
|
199 |
-
{//then this is also a child with the same parent so don't change depth
|
200 |
-
|
201 |
-
}
|
202 |
-
else
|
203 |
-
{//then this has a different parent so must be lower depth
|
204 |
-
if($this->multidepth>0)
|
205 |
-
{
|
206 |
-
$this->multidepth--;
|
207 |
-
}
|
208 |
-
}
|
209 |
-
|
210 |
-
$pad = str_repeat(' ', $this->multidepth * 3);
|
211 |
-
$link = "<option class=\"level-".$this->multidepth."\" value='".$cat_id."'$checked />".$pad.$cat_name;
|
212 |
-
|
213 |
-
if ( !empty($show_count) )
|
214 |
-
$link .= ' (' . intval($category->count) . ')';
|
215 |
-
|
216 |
-
|
217 |
-
$link .= "</option>";
|
218 |
-
$output .= "\t$link\n";
|
219 |
-
|
220 |
-
|
221 |
-
$this->multilastid = $cat_id;
|
222 |
-
|
223 |
-
|
224 |
-
/*
|
225 |
-
$pad = str_repeat(' ', $depth * 3);
|
226 |
-
|
227 |
-
$output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
|
228 |
-
$cat_name = apply_filters('list_cats', $category->name, $category);
|
229 |
-
if ( $category->term_id == $args['selected'] )
|
230 |
-
$output .= ' selected="selected"';
|
231 |
-
$output .= '>';
|
232 |
-
$output .= $pad.$cat_name;
|
233 |
-
if ( $args['show_count'] )
|
234 |
-
$output .= ' ('. $category->count .')';
|
235 |
-
$output .= "</option>\n";*/
|
236 |
-
}
|
237 |
-
|
238 |
-
|
239 |
-
}
|
240 |
-
|
241 |
-
function end_el( &$output, $page, $depth = 0, $args = array() )
|
242 |
-
{
|
243 |
-
if($this->type=="list")
|
244 |
-
{
|
245 |
-
if ( 'list' != $args['style'] )
|
246 |
-
return;
|
247 |
-
|
248 |
-
$output .= "</li>\n";
|
249 |
-
}
|
250 |
-
else if(($this->type=="checkbox")||($this->type=="radio"))
|
251 |
-
{
|
252 |
-
if ( 'list' != $args['style'] )
|
253 |
-
return;
|
254 |
-
|
255 |
-
$output .= "</li>\n";
|
256 |
-
}
|
257 |
-
else if($this->type=="multiselect")
|
258 |
-
{
|
259 |
-
if ( 'list' != $args['style'] )
|
260 |
-
return;
|
261 |
-
|
262 |
-
$output .= "</option>\n";
|
263 |
-
}
|
264 |
-
}
|
265 |
-
|
266 |
-
function start_lvl( &$output, $depth = 0, $args = array() )
|
267 |
-
{
|
268 |
-
|
269 |
-
if($this->type=="list")
|
270 |
-
{
|
271 |
-
if ( 'list' != $args['style'] )
|
272 |
-
return;
|
273 |
-
|
274 |
-
$indent = str_repeat("\t", $depth);
|
275 |
-
$output .= "$indent<ul class='children'>\n";
|
276 |
-
}
|
277 |
-
else if(($this->type=="checkbox")||($this->type=="radio"))
|
278 |
-
{
|
279 |
-
if ( 'list' != $args['style'] )
|
280 |
-
return;
|
281 |
-
|
282 |
-
$indent = str_repeat("\t", $depth);
|
283 |
-
$output .= "$indent<ul class='children'>\n";
|
284 |
-
}
|
285 |
-
else if($this->type=="multiselect")
|
286 |
-
{
|
287 |
-
/*if ( 'list' != $args['style'] )
|
288 |
-
return;
|
289 |
-
|
290 |
-
$indent = str_repeat("\t", $depth);
|
291 |
-
$output .= "$indent<ul class='children'>\n";*/
|
292 |
-
}
|
293 |
-
}
|
294 |
-
|
295 |
-
function end_lvl( &$output, $depth = 0, $args = array() ) {
|
296 |
-
if($this->type=="list")
|
297 |
-
{
|
298 |
-
if ( 'list' != $args['style'] )
|
299 |
-
return;
|
300 |
-
|
301 |
-
$indent = str_repeat("\t", $depth);
|
302 |
-
$output .= "$indent</ul>\n";
|
303 |
-
}
|
304 |
-
else if(($this->type=="checkbox")||($this->type=="radio"))
|
305 |
-
{
|
306 |
-
if ( 'list' != $args['style'] )
|
307 |
-
return;
|
308 |
-
|
309 |
-
$indent = str_repeat("\t", $depth);
|
310 |
-
$output .= "$indent</ul>\n";
|
311 |
-
}
|
312 |
-
else if($this->type=="multiselect")
|
313 |
-
{
|
314 |
-
|
315 |
-
}
|
316 |
-
}
|
317 |
-
}
|
318 |
-
|
319 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Taxonomy_Walker extends Walker_Category {
|
4 |
+
|
5 |
+
|
6 |
+
private $type = '';
|
7 |
+
private $defaults = array();
|
8 |
+
private $multidepth = 0; //manually calculate depth on multiselects
|
9 |
+
private $multilastid = 0; //manually calculate depth on multiselects
|
10 |
+
private $multilastdepthchange = 0; //manually calculate depth on multiselects
|
11 |
+
|
12 |
+
function __construct($type = 'checkbox', $defaults = array()) {
|
13 |
+
// fetch the list of term ids for the given post
|
14 |
+
//$this->term_ids = wp_get_post_terms( $post_id, $taxonomy, 'fields=ids' );
|
15 |
+
//var_dump($this->term_ids);
|
16 |
+
|
17 |
+
$this->type = $type;
|
18 |
+
$this->defaults = $defaults;
|
19 |
+
}
|
20 |
+
|
21 |
+
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
|
22 |
+
/*$display = false;
|
23 |
+
|
24 |
+
$id = $element->term_id;
|
25 |
+
|
26 |
+
$display = true;
|
27 |
+
if ( isset( $children_elements[ $id ] ) ) {
|
28 |
+
// the current term has children
|
29 |
+
foreach ( $children_elements[ $id ] as $child ) {
|
30 |
+
if ( in_array( $child->term_id, $this->term_ids ) ) {
|
31 |
+
// one of the term's children is in the list
|
32 |
+
$display = true;
|
33 |
+
// can stop searching now
|
34 |
+
break;
|
35 |
+
}
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
if ( $display )*/
|
40 |
+
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 )
|
45 |
+
{
|
46 |
+
|
47 |
+
if($this->type=="list")
|
48 |
+
{
|
49 |
+
extract($args);
|
50 |
+
|
51 |
+
$cat_name = esc_attr( $category->name );
|
52 |
+
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
53 |
+
$link = '<a href="' . esc_url( get_term_link($category) ) . '" ';
|
54 |
+
if ( $use_desc_for_title == 0 || empty($category->description) )
|
55 |
+
$link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
|
56 |
+
else
|
57 |
+
$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
|
58 |
+
$link .= '>';
|
59 |
+
$link .= $cat_name . '</a>';
|
60 |
+
|
61 |
+
if ( !empty($feed_image) || !empty($feed) ) {
|
62 |
+
$link .= ' ';
|
63 |
+
|
64 |
+
if ( empty($feed_image) )
|
65 |
+
$link .= '(';
|
66 |
+
|
67 |
+
$link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) ) . '"';
|
68 |
+
|
69 |
+
if ( empty($feed) ) {
|
70 |
+
$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
|
71 |
+
} else {
|
72 |
+
$title = ' title="' . $feed . '"';
|
73 |
+
$alt = ' alt="' . $feed . '"';
|
74 |
+
$name = $feed;
|
75 |
+
$link .= $title;
|
76 |
+
}
|
77 |
+
|
78 |
+
$link .= '>';
|
79 |
+
|
80 |
+
if ( empty($feed_image) )
|
81 |
+
$link .= $name;
|
82 |
+
else
|
83 |
+
$link .= "<img src='$feed_image'$alt$title" . ' />';
|
84 |
+
|
85 |
+
$link .= '</a>';
|
86 |
+
|
87 |
+
if ( empty($feed_image) )
|
88 |
+
$link .= ')';
|
89 |
+
}
|
90 |
+
|
91 |
+
if ( !empty($show_count) )
|
92 |
+
$link .= ' (' . intval($category->count) . ')';
|
93 |
+
|
94 |
+
if ( 'list' == $args['style'] ) {
|
95 |
+
$output .= "\t<li";
|
96 |
+
$class = 'cat-item cat-item-' . $category->term_id;
|
97 |
+
if ( !empty($current_category) ) {
|
98 |
+
$_current_category = get_term( $current_category, $category->taxonomy );
|
99 |
+
if ( $category->term_id == $current_category )
|
100 |
+
$class .= ' current-cat';
|
101 |
+
elseif ( $category->term_id == $_current_category->parent )
|
102 |
+
$class .= ' current-cat-parent';
|
103 |
+
}
|
104 |
+
$output .= ' class="' . $class . '"';
|
105 |
+
$output .= ">$link\n";
|
106 |
+
} else {
|
107 |
+
$output .= "\t$link<br />\n";
|
108 |
+
}
|
109 |
+
}
|
110 |
+
else if(($this->type=="checkbox")||($this->type=="radio"))
|
111 |
+
{
|
112 |
+
extract($args);
|
113 |
+
|
114 |
+
$cat_name = esc_attr( $category->name );
|
115 |
+
$cat_id = esc_attr( $category->term_id );
|
116 |
+
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
117 |
+
|
118 |
+
//check a default has been set
|
119 |
+
$checked = "";
|
120 |
+
if($defaults)
|
121 |
+
{
|
122 |
+
$noselected = count($this->defaults);
|
123 |
+
|
124 |
+
if(($noselected>0)&&(is_array($defaults)))
|
125 |
+
{
|
126 |
+
foreach($defaults as $defaultid)
|
127 |
+
{
|
128 |
+
if($defaultid==$cat_id)
|
129 |
+
{
|
130 |
+
$checked = ' checked="checked"';
|
131 |
+
}
|
132 |
+
}
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
$link = "<label><input type='".$this->type."' name='".$name."[]' value='".$cat_id."'".$checked." /> ".$cat_name;
|
137 |
+
|
138 |
+
|
139 |
+
if ( !empty($show_count) )
|
140 |
+
$link .= ' (' . intval($category->count) . ')';
|
141 |
+
|
142 |
+
|
143 |
+
$link .= "</label>";
|
144 |
+
|
145 |
+
if ( 'list' == $args['style'] ) {
|
146 |
+
$output .= "\t<li";
|
147 |
+
$class = 'cat-item cat-item-' . $category->term_id;
|
148 |
+
if ( !empty($current_category) ) {
|
149 |
+
$_current_category = get_term( $current_category, $category->taxonomy );
|
150 |
+
if ( $category->term_id == $current_category )
|
151 |
+
$class .= ' current-cat';
|
152 |
+
elseif ( $category->term_id == $_current_category->parent )
|
153 |
+
$class .= ' current-cat-parent';
|
154 |
+
}
|
155 |
+
$output .= ' class="' . $class . '"';
|
156 |
+
$output .= ">$link\n";
|
157 |
+
} else {
|
158 |
+
$output .= "\t$link<br />\n";
|
159 |
+
}
|
160 |
+
}
|
161 |
+
else if($this->type=="multiselect")
|
162 |
+
{
|
163 |
+
extract($args);
|
164 |
+
|
165 |
+
$cat_name = esc_attr( $category->name );
|
166 |
+
$cat_id = esc_attr( $category->term_id );
|
167 |
+
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
168 |
+
|
169 |
+
//check a default has been set
|
170 |
+
$checked = "";
|
171 |
+
if($defaults)
|
172 |
+
{
|
173 |
+
$noselected = count($this->defaults);
|
174 |
+
|
175 |
+
if(($noselected>0)&&(is_array($defaults)))
|
176 |
+
{
|
177 |
+
foreach($defaults as $defaultid)
|
178 |
+
{
|
179 |
+
if($defaultid==$cat_id)
|
180 |
+
{
|
181 |
+
$checked = ' selected="selected"';
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
}
|
186 |
+
|
187 |
+
|
188 |
+
/* Custom depth calculations! :/ */
|
189 |
+
if($category->parent == 0)
|
190 |
+
{//then this has no parent so reset depth
|
191 |
+
$this->multidepth = 0;
|
192 |
+
}
|
193 |
+
else if($category->parent == $this->multilastid)
|
194 |
+
{
|
195 |
+
$this->multidepth++;
|
196 |
+
$this->multilastdepthchange = $this->multilastid;
|
197 |
+
}
|
198 |
+
else if($category->parent == $this->multilastdepthchange)
|
199 |
+
{//then this is also a child with the same parent so don't change depth
|
200 |
+
|
201 |
+
}
|
202 |
+
else
|
203 |
+
{//then this has a different parent so must be lower depth
|
204 |
+
if($this->multidepth>0)
|
205 |
+
{
|
206 |
+
$this->multidepth--;
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
$pad = str_repeat(' ', $this->multidepth * 3);
|
211 |
+
$link = "<option class=\"level-".$this->multidepth."\" value='".$cat_id."'$checked />".$pad.$cat_name;
|
212 |
+
|
213 |
+
if ( !empty($show_count) )
|
214 |
+
$link .= ' (' . intval($category->count) . ')';
|
215 |
+
|
216 |
+
|
217 |
+
$link .= "</option>";
|
218 |
+
$output .= "\t$link\n";
|
219 |
+
|
220 |
+
|
221 |
+
$this->multilastid = $cat_id;
|
222 |
+
|
223 |
+
|
224 |
+
/*
|
225 |
+
$pad = str_repeat(' ', $depth * 3);
|
226 |
+
|
227 |
+
$output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
|
228 |
+
$cat_name = apply_filters('list_cats', $category->name, $category);
|
229 |
+
if ( $category->term_id == $args['selected'] )
|
230 |
+
$output .= ' selected="selected"';
|
231 |
+
$output .= '>';
|
232 |
+
$output .= $pad.$cat_name;
|
233 |
+
if ( $args['show_count'] )
|
234 |
+
$output .= ' ('. $category->count .')';
|
235 |
+
$output .= "</option>\n";*/
|
236 |
+
}
|
237 |
+
|
238 |
+
|
239 |
+
}
|
240 |
+
|
241 |
+
function end_el( &$output, $page, $depth = 0, $args = array() )
|
242 |
+
{
|
243 |
+
if($this->type=="list")
|
244 |
+
{
|
245 |
+
if ( 'list' != $args['style'] )
|
246 |
+
return;
|
247 |
+
|
248 |
+
$output .= "</li>\n";
|
249 |
+
}
|
250 |
+
else if(($this->type=="checkbox")||($this->type=="radio"))
|
251 |
+
{
|
252 |
+
if ( 'list' != $args['style'] )
|
253 |
+
return;
|
254 |
+
|
255 |
+
$output .= "</li>\n";
|
256 |
+
}
|
257 |
+
else if($this->type=="multiselect")
|
258 |
+
{
|
259 |
+
if ( 'list' != $args['style'] )
|
260 |
+
return;
|
261 |
+
|
262 |
+
$output .= "</option>\n";
|
263 |
+
}
|
264 |
+
}
|
265 |
+
|
266 |
+
function start_lvl( &$output, $depth = 0, $args = array() )
|
267 |
+
{
|
268 |
+
|
269 |
+
if($this->type=="list")
|
270 |
+
{
|
271 |
+
if ( 'list' != $args['style'] )
|
272 |
+
return;
|
273 |
+
|
274 |
+
$indent = str_repeat("\t", $depth);
|
275 |
+
$output .= "$indent<ul class='children'>\n";
|
276 |
+
}
|
277 |
+
else if(($this->type=="checkbox")||($this->type=="radio"))
|
278 |
+
{
|
279 |
+
if ( 'list' != $args['style'] )
|
280 |
+
return;
|
281 |
+
|
282 |
+
$indent = str_repeat("\t", $depth);
|
283 |
+
$output .= "$indent<ul class='children'>\n";
|
284 |
+
}
|
285 |
+
else if($this->type=="multiselect")
|
286 |
+
{
|
287 |
+
/*if ( 'list' != $args['style'] )
|
288 |
+
return;
|
289 |
+
|
290 |
+
$indent = str_repeat("\t", $depth);
|
291 |
+
$output .= "$indent<ul class='children'>\n";*/
|
292 |
+
}
|
293 |
+
}
|
294 |
+
|
295 |
+
function end_lvl( &$output, $depth = 0, $args = array() ) {
|
296 |
+
if($this->type=="list")
|
297 |
+
{
|
298 |
+
if ( 'list' != $args['style'] )
|
299 |
+
return;
|
300 |
+
|
301 |
+
$indent = str_repeat("\t", $depth);
|
302 |
+
$output .= "$indent</ul>\n";
|
303 |
+
}
|
304 |
+
else if(($this->type=="checkbox")||($this->type=="radio"))
|
305 |
+
{
|
306 |
+
if ( 'list' != $args['style'] )
|
307 |
+
return;
|
308 |
+
|
309 |
+
$indent = str_repeat("\t", $depth);
|
310 |
+
$output .= "$indent</ul>\n";
|
311 |
+
}
|
312 |
+
else if($this->type=="multiselect")
|
313 |
+
{
|
314 |
+
|
315 |
+
}
|
316 |
+
}
|
317 |
+
}
|
318 |
+
|
319 |
?>
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: DesignsAndCode
|
|
3 |
Donate link:
|
4 |
Tags: category, filter, taxonomy, search, wordpress, post type, post date
|
5 |
Requires at least: 3.5
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 1.2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -34,6 +34,12 @@ The documentation has been updated to include examples almost all configurable o
|
|
34 |
|
35 |
== Changelog ==
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
= 1.2.4 =
|
38 |
* Fixed a bug created in 1.2.3 when doing an empty search
|
39 |
|
@@ -107,13 +113,32 @@ The documentation has been updated to include examples almost all configurable o
|
|
107 |
|
108 |
== Description ==
|
109 |
|
110 |
-
Search & Filter is a simple search and filtering plugin for WordPress
|
111 |
-
|
112 |
-
You can search by Category, Tag, Custom Taxonomy, Post Type, Post Date or any combination of these easily
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
-
* [Search & Filter Documentation](http://docs.designsandcode.com/search-filter/)
|
117 |
-
* [Search & Filter Discussion](http://www.designsandcode.com/447/wordpress-search-filter-plugin-for-taxonomies/)
|
118 |
|
119 |
|
3 |
Donate link:
|
4 |
Tags: category, filter, taxonomy, search, wordpress, post type, post date
|
5 |
Requires at least: 3.5
|
6 |
+
Tested up to: 4
|
7 |
+
Stable tag: 1.2.5
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
34 |
|
35 |
== Changelog ==
|
36 |
|
37 |
+
= 1.2.5 =
|
38 |
+
* Fixed a PHP error when setting defaults for taxonomies - many users did not see this but resulted in unexpected behaviour
|
39 |
+
* Fixed an error with post date sometimes being undefined for blank searches
|
40 |
+
* Added argument `empty_search_url` - when a users submits the search form without any search preferences selected they will be redirected to this URL
|
41 |
+
* Updated argument `add_search_param` - setting to `1` will force add a "?s=" to all urls generate by the plugin - this may help with the loading of search templates in some themes
|
42 |
+
|
43 |
= 1.2.4 =
|
44 |
* Fixed a bug created in 1.2.3 when doing an empty search
|
45 |
|
113 |
|
114 |
== Description ==
|
115 |
|
116 |
+
Search & Filter is a simple search and filtering plugin for WordPress - it is an advancement of the WordPress search box.
|
117 |
+
|
118 |
+
You can search by Category, Tag, Custom Taxonomy, Post Type, Post Date or any combination of these easily to really refine your searches - remove the search box and use it as a filtering system for your posts and pages. Fields can be displayed as dropdowns, checkboxes, radio buttons or multi selects.
|
119 |
+
|
120 |
+
**Links:** [Search & Filter Documentation](http://docs.designsandcode.com/search-filter/) | [Search & Filter Discussion](http://www.designsandcode.com/447/wordpress-search-filter-plugin-for-taxonomies/)
|
121 |
+
|
122 |
+
= New: Search & Filter Pro =
|
123 |
+
|
124 |
+
|
125 |
+
* View live demo >> [demo 1](http://demo.designsandcode.com/sfpro-movie-reviews/) | [demo 2](http://demo.designsandcode.com/sfpro-woo-mystile/product-search/) | [video](http://www.designsandcode.com/wordpress-plugins/search-filter-pro/)
|
126 |
+
* Search **Custom Fields**, **Post Meta**, **Authors**, Post Types, Post Dates, Taxonomies, Tags, Categories
|
127 |
+
* Use **AJAX** to display results - no more page reloading!
|
128 |
+
* Search **Post Meta/Custom Fields** with checkboxes, radio buttons, dropdowns, multiselects or comboboxes
|
129 |
+
* jQuery range slider, date pickers and **auto-complete comboboxes** for selects and multiselects
|
130 |
+
* Order Results Field - users can order results by meta value, Post ID, author, title, name, date, date modified, parent ID, random, comment count and menu order
|
131 |
+
* Drag & Drop editor
|
132 |
+
* Use custom templates
|
133 |
+
* Create as many fields and different search forms as you like
|
134 |
+
* Use for blogs, reviews sites, news sites, property sites and more.
|
135 |
+
* Use for your online shop - tested and compatible with **WooCommerce**, **WP eCommerce**, **Easy Digital Downloads**
|
136 |
+
* Place anywhere in your themes and posts using shortcodes and widgets
|
137 |
+
* Works with **WPML**
|
138 |
+
* Works with **Advanced Custom Fields**
|
139 |
+
* Extremely easy to use admin UI, fully integrated with WP 3.8+
|
140 |
+
* **Dedicated Support**
|
141 |
+
* [More info >>](http://www.designsandcode.com/wordpress-plugins/search-filter-pro/)
|
142 |
|
|
|
|
|
143 |
|
144 |
|
search-filter.php
CHANGED
@@ -1,1690 +1,1724 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Search & Filter
|
4 |
-
Plugin URI: http://www.designsandcode.com/447/wordpress-search-filter-plugin-for-taxonomies/
|
5 |
-
Description: Search and Filtering system for Pages, Posts, Categories, Tags and Taxonomies
|
6 |
-
Author: Designs & Code
|
7 |
-
Author URI: http://www.designsandcode.com/
|
8 |
-
Version: 1.2.
|
9 |
-
Text Domain: searchandfilter
|
10 |
-
License: GPLv2
|
11 |
-
*/
|
12 |
-
|
13 |
-
// TO DO - i18n http://codex.wordpress.org/I18n_for_WordPress_Developers
|
14 |
-
|
15 |
-
/*
|
16 |
-
* Set up Plugin Globals
|
17 |
-
*/
|
18 |
-
if (!defined('SEARCHANDFILTER_VERSION_NUM'))
|
19 |
-
define('SEARCHANDFILTER_VERSION_NUM', '1.2.
|
20 |
-
|
21 |
-
if (!defined('SEARCHANDFILTER_THEME_DIR'))
|
22 |
-
define('SEARCHANDFILTER_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
|
23 |
-
|
24 |
-
if (!defined('SEARCHANDFILTER_PLUGIN_NAME'))
|
25 |
-
define('SEARCHANDFILTER_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
|
26 |
-
|
27 |
-
if (!defined('SEARCHANDFILTER_PLUGIN_DIR'))
|
28 |
-
define('SEARCHANDFILTER_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . SEARCHANDFILTER_PLUGIN_NAME);
|
29 |
-
|
30 |
-
if (!defined('SEARCHANDFILTER_PLUGIN_URL'))
|
31 |
-
define('SEARCHANDFILTER_PLUGIN_URL', WP_PLUGIN_URL . '/' . SEARCHANDFILTER_PLUGIN_NAME);
|
32 |
-
|
33 |
-
if (!defined('SEARCHANDFILTER_BASENAME'))
|
34 |
-
define('SEARCHANDFILTER_BASENAME', plugin_basename(__FILE__));
|
35 |
-
|
36 |
-
if (!defined('SEARCHANDFILTER_VERSION_KEY'))
|
37 |
-
define('SEARCHANDFILTER_VERSION_KEY', 'searchandfilter_version');
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
//form prefix for plugin
|
42 |
-
if (!defined('SF_FPRE'))
|
43 |
-
define('SF_FPRE', 'of');
|
44 |
-
|
45 |
-
add_option(SEARCHANDFILTER_VERSION_KEY, SEARCHANDFILTER_VERSION_NUM);
|
46 |
-
|
47 |
-
/*
|
48 |
-
* Set up Plugin Globals
|
49 |
-
*/
|
50 |
-
if ( ! class_exists( 'SearchAndFilter' ) )
|
51 |
-
{
|
52 |
-
class SearchAndFilter
|
53 |
-
{
|
54 |
-
private $has_form_posted = false;
|
55 |
-
private $hasqmark = false;
|
56 |
-
private $hassearchquery = false;
|
57 |
-
private $urlparams = "/";
|
58 |
-
private $searchterm = "";
|
59 |
-
private $tagid = 0;
|
60 |
-
private $catid = 0;
|
61 |
-
private $defaults = array();
|
62 |
-
private $frmreserved = array();
|
63 |
-
private $taxonomylist = array();
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
$this->
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
add_filter('pre_get_posts', array($this,'
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
add_action( '
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
wp_enqueue_style( '
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
'
|
115 |
-
'
|
116 |
-
'
|
117 |
-
'
|
118 |
-
'
|
119 |
-
'
|
120 |
-
'
|
121 |
-
'
|
122 |
-
'
|
123 |
-
'
|
124 |
-
'
|
125 |
-
'
|
126 |
-
'
|
127 |
-
'
|
128 |
-
'
|
129 |
-
'
|
130 |
-
'
|
131 |
-
'
|
132 |
-
|
133 |
-
), $atts));
|
134 |
-
|
135 |
-
//init `fields`
|
136 |
-
if($fields!=null)
|
137 |
-
{
|
138 |
-
$fields = explode(",",$fields);
|
139 |
-
}
|
140 |
-
else
|
141 |
-
{
|
142 |
-
$fields = explode(",",$taxonomies);
|
143 |
-
}
|
144 |
-
|
145 |
-
$this->taxonomylist = $fields;
|
146 |
-
$nofields = count($fields);
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
//
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
$labels
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
$all_items_labels
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
//Loop through Fields and set up default vars
|
284 |
-
for($i=0; $i<$nofields; $i++)
|
285 |
-
{//loop through all fields
|
286 |
-
|
287 |
-
//set up types
|
288 |
-
if(isset($types[$i]))
|
289 |
-
{
|
290 |
-
if($fields[$i] == 'post_date')
|
291 |
-
{//check for post date field
|
292 |
-
|
293 |
-
if(($types[$i]!="date")&&($types[$i]!="daterange"))
|
294 |
-
{//if not expected value
|
295 |
-
|
296 |
-
$types[$i] = "date"; //use default
|
297 |
-
}
|
298 |
-
}
|
299 |
-
else
|
300 |
-
{//everything else can use a standard form input - checkbox/radio/dropdown/list/multiselect
|
301 |
-
|
302 |
-
if(($types[$i]!="select")&&($types[$i]!="checkbox")&&($types[$i]!="radio")&&($types[$i]!="list")&&($types[$i]!="multiselect"))
|
303 |
-
{//no accepted type matched - non compatible type defined by user
|
304 |
-
|
305 |
-
$types[$i] = "select"; //use default
|
306 |
-
}
|
307 |
-
}
|
308 |
-
}
|
309 |
-
else
|
310 |
-
{//omitted, so set default
|
311 |
-
|
312 |
-
if($fields[$i] == 'post_date')
|
313 |
-
{
|
314 |
-
$types[$i] = "date";
|
315 |
-
}
|
316 |
-
else
|
317 |
-
{
|
318 |
-
$types[$i] = "select";
|
319 |
-
}
|
320 |
-
}
|
321 |
-
|
322 |
-
//setup labels
|
323 |
-
if(!isset($labels[$i]))
|
324 |
-
{
|
325 |
-
$labels[$i] = "";
|
326 |
-
}
|
327 |
-
|
328 |
-
//setup all_items_labels
|
329 |
-
if(!isset($all_items_labels[$i]))
|
330 |
-
{
|
331 |
-
$all_items_labels[$i] = "";
|
332 |
-
}
|
333 |
-
|
334 |
-
|
335 |
-
if(isset($order_by[$i]))
|
336 |
-
{
|
337 |
-
if(($order_by[$i]!="id")&&($order_by[$i]!="name")&&($order_by[$i]!="slug")&&($order_by[$i]!="count")&&($order_by[$i]!="term_group"))
|
338 |
-
{
|
339 |
-
$order_by[$i] = "name"; //use default - possible typo or use of unknown value
|
340 |
-
}
|
341 |
-
}
|
342 |
-
else
|
343 |
-
{
|
344 |
-
$order_by[$i] = "name"; //use default
|
345 |
-
}
|
346 |
-
|
347 |
-
if(isset($order_dir[$i]))
|
348 |
-
{
|
349 |
-
if(($order_dir[$i]!="asc")&&($order_dir[$i]!="desc"))
|
350 |
-
{//then order_dir is not a wanted value
|
351 |
-
|
352 |
-
$order_dir[$i] = "asc"; //set to default
|
353 |
-
}
|
354 |
-
}
|
355 |
-
else
|
356 |
-
{
|
357 |
-
$order_dir[$i] = "asc"; //use default
|
358 |
-
}
|
359 |
-
|
360 |
-
if(isset($operators[$i]))
|
361 |
-
{
|
362 |
-
if(($operators[$i]!="and")&&($operators[$i]!="or"))
|
363 |
-
{
|
364 |
-
$operators[$i] = "and"; //else use default - possible typo or use of unknown value
|
365 |
-
}
|
366 |
-
}
|
367 |
-
else
|
368 |
-
{
|
369 |
-
$operators[$i] = "and"; //use default
|
370 |
-
}
|
371 |
-
|
372 |
-
}
|
373 |
-
|
374 |
-
//set all form defaults / dropdowns etc
|
375 |
-
$this->set_defaults();
|
376 |
-
|
377 |
-
return $this->get_search_filter_form($submit_label, $search_placeholder, $fields, $types, $labels, $hierarchical, $hide_empty, $show_count, $post_types, $order_by, $order_dir, $operators, $all_items_labels, $class);
|
378 |
-
}
|
379 |
-
|
380 |
-
|
381 |
-
function add_queryvars( $qvars )
|
382 |
-
{
|
383 |
-
$qvars[] = 'post_types';
|
384 |
-
$qvars[] = 'post_date';
|
385 |
-
return $qvars;
|
386 |
-
}
|
387 |
-
|
388 |
-
function filter_query_post_types($query)
|
389 |
-
{
|
390 |
-
global $wp_query;
|
391 |
-
|
392 |
-
if(($query->is_main_query())&&(!is_admin()))
|
393 |
-
{
|
394 |
-
if(isset($wp_query->query['post_types']))
|
395 |
-
{
|
396 |
-
$search_all = false;
|
397 |
-
|
398 |
-
$post_types = explode(",",esc_attr($wp_query->query['post_types']));
|
399 |
-
if(isset($post_types[0]))
|
400 |
-
{
|
401 |
-
if(count($post_types)==1)
|
402 |
-
{
|
403 |
-
if($post_types[0]=="all")
|
404 |
-
{
|
405 |
-
$search_all = true;
|
406 |
-
}
|
407 |
-
}
|
408 |
-
}
|
409 |
-
if($search_all)
|
410 |
-
{
|
411 |
-
$post_types = get_post_types( '', 'names' );
|
412 |
-
$query->set('post_type', $post_types); //here we set the post types that we want WP to search
|
413 |
-
}
|
414 |
-
else
|
415 |
-
{
|
416 |
-
$query->set('post_type', $post_types); //here we set the post types that we want WP to search
|
417 |
-
}
|
418 |
-
}
|
419 |
-
}
|
420 |
-
|
421 |
-
return $query;
|
422 |
-
}
|
423 |
-
|
424 |
-
|
425 |
-
function limit_date_range_query( $where )
|
426 |
-
{
|
427 |
-
global $wp_query;
|
428 |
-
|
429 |
-
//get post dates into array
|
430 |
-
$post_date = explode("+", esc_attr(urlencode($wp_query->query['post_date'])));
|
431 |
-
|
432 |
-
if (count($post_date) > 1 && $post_date[0] != $post_date[1])
|
433 |
-
{
|
434 |
-
$date_query = array();
|
435 |
-
|
436 |
-
if (!empty($post_date[0]))
|
437 |
-
{
|
438 |
-
$date_query['after'] = date('Y-m-d 00:00:00', strtotime($post_date[0]));
|
439 |
-
}
|
440 |
-
|
441 |
-
if (!empty($post_date[1]))
|
442 |
-
{
|
443 |
-
$date_query['before'] = date('Y-m-d 23:59:59', strtotime($post_date[1]));
|
444 |
-
}
|
445 |
-
|
446 |
-
}
|
447 |
-
|
448 |
-
// Append fragment to WHERE clause to select posts newer than the past week.
|
449 |
-
$where .= " AND post_date >='" . $date_query['after'] . "' AND post_date <='" . $date_query['before'] . "'";
|
450 |
-
|
451 |
-
return $where;
|
452 |
-
}
|
453 |
-
|
454 |
-
/**
|
455 |
-
* Remove the filter limiting posts to the past week.
|
456 |
-
*
|
457 |
-
* Remove the filter after it runs so that it doesn't affect any other
|
458 |
-
* queries that might be performed on the same page (eg. Recent Posts
|
459 |
-
* widget).
|
460 |
-
*/
|
461 |
-
function remove_limit_date_range_query()
|
462 |
-
{
|
463 |
-
remove_filter( 'posts_where', 'limit_date_range_query' );
|
464 |
-
}
|
465 |
-
|
466 |
-
function fix_blank_search($query)
|
467 |
-
{//needs to be re-implemented
|
468 |
-
|
469 |
-
if((isset($_GET['s'])) && (empty($_GET['s'])) && ($query->is_main_query()))
|
470 |
-
{
|
471 |
-
$query->is_search = true;
|
472 |
-
$query->is_home = false;
|
473 |
-
}
|
474 |
-
|
475 |
-
}
|
476 |
-
|
477 |
-
function filter_query_post_date($query)
|
478 |
-
{
|
479 |
-
global $wp_query;
|
480 |
-
|
481 |
-
if(($query->is_main_query())&&(!is_admin()))
|
482 |
-
{
|
483 |
-
if(isset($wp_query->query['post_date']))
|
484 |
-
{
|
485 |
-
//get post dates into array
|
486 |
-
$post_date = explode("+", esc_attr(urlencode($wp_query->query['post_date'])));
|
487 |
-
|
488 |
-
if(!empty($post_date))
|
489 |
-
{
|
490 |
-
//if there is more than 1 post date and the dates are not the same
|
491 |
-
if (count($post_date) > 1 && $post_date[0] != $post_date[1])
|
492 |
-
{
|
493 |
-
if((!empty($post_date[0]))&&(!empty($post_date[1])))
|
494 |
-
{
|
495 |
-
// Attach hook to filter WHERE clause.
|
496 |
-
add_filter('posts_where', array($this,'limit_date_range_query'));
|
497 |
-
|
498 |
-
// Remove the filter after it is executed.
|
499 |
-
add_action('posts_selection', array($this,'remove_limit_date_range_query'));
|
500 |
-
}
|
501 |
-
}
|
502 |
-
else
|
503 |
-
{ //else we are dealing with one date or both dates are the same (so need to find posts for a single day)
|
504 |
-
|
505 |
-
if (!empty($post_date[0]))
|
506 |
-
{
|
507 |
-
$post_time = strtotime($post_date[0]);
|
508 |
-
$query->set('year', date('Y', $post_time));
|
509 |
-
$query->set('monthnum', date('m', $post_time));
|
510 |
-
$query->set('day', date('d', $post_time));
|
511 |
-
}
|
512 |
-
}
|
513 |
-
}
|
514 |
-
}
|
515 |
-
}
|
516 |
-
|
517 |
-
return $query;
|
518 |
-
}
|
519 |
-
|
520 |
-
/*
|
521 |
-
* check to set defaults - to be called after the shortcodes have been init so we can grab the wanted list of fields
|
522 |
-
*/
|
523 |
-
public function set_defaults()
|
524 |
-
{
|
525 |
-
global $wp_query;
|
526 |
-
|
527 |
-
$categories = array();
|
528 |
-
|
529 |
-
if(isset($wp_query->query['category_name']))
|
530 |
-
{
|
531 |
-
$category_params = (preg_split("/[,\+ ]/", esc_attr($wp_query->query['category_name']))); //explode with 2 delims
|
532 |
-
|
533 |
-
//$category_params = explode("+",esc_attr($wp_query->query['category_name']));
|
534 |
-
|
535 |
-
foreach($category_params as $category_param)
|
536 |
-
{
|
537 |
-
$category = get_category_by_slug( $category_param );
|
538 |
-
if(isset($category->cat_ID))
|
539 |
-
{
|
540 |
-
$categories[] = $category->cat_ID;
|
541 |
-
}
|
542 |
-
}
|
543 |
-
}
|
544 |
-
|
545 |
-
$this->defaults[SF_FPRE.'category'] = $categories;
|
546 |
-
|
547 |
-
|
548 |
-
//grab search term for prefilling search input
|
549 |
-
if(isset($wp_query->query['s']))
|
550 |
-
{//!"�$%^&*()
|
551 |
-
$this->searchterm = trim(get_search_query());
|
552 |
-
}
|
553 |
-
|
554 |
-
//check to see if tag is set
|
555 |
-
|
556 |
-
$tags = array();
|
557 |
-
|
558 |
-
if(isset($wp_query->query['tag']))
|
559 |
-
{
|
560 |
-
$tag_params = (preg_split("/[,\+ ]/", esc_attr($wp_query->query['tag']))); //explode with 2 delims
|
561 |
-
//$tag_params = explode("+",esc_attr($wp_query->query['tag']));
|
562 |
-
|
563 |
-
foreach($tag_params as $tag_param)
|
564 |
-
{
|
565 |
-
$tag = get_term_by("slug",$tag_param, "post_tag");
|
566 |
-
if(isset($tag->term_id))
|
567 |
-
{
|
568 |
-
$tags[] = $tag->term_id;
|
569 |
-
}
|
570 |
-
}
|
571 |
-
}
|
572 |
-
|
573 |
-
$this->defaults[SF_FPRE.'post_tag'] = $tags;
|
574 |
-
|
575 |
-
$taxs = array();
|
576 |
-
//loop through all the query vars
|
577 |
-
foreach($wp_query->query as $key=>$val)
|
578 |
-
{
|
579 |
-
if(!in_array(SF_FPRE.$key, $this->frmqreserved))
|
580 |
-
{//make sure the get is not a reserved get as they have already been handled above
|
581 |
-
|
582 |
-
//now check it is a desired key
|
583 |
-
if(in_array($key, $this->taxonomylist))
|
584 |
-
{
|
585 |
-
$taxslug = ($val);
|
586 |
-
//$tax_params = explode("+",esc_attr($taxslug));
|
587 |
-
|
588 |
-
$tax_params = (preg_split("/[,\+ ]/", esc_attr($taxslug))); //explode with 2 delims
|
589 |
-
|
590 |
-
foreach($tax_params as $tax_param)
|
591 |
-
{
|
592 |
-
$tax = get_term_by("slug",$tax_param, $key);
|
593 |
-
|
594 |
-
if(isset($tax->term_id))
|
595 |
-
{
|
596 |
-
$taxs[] = $tax->term_id;
|
597 |
-
}
|
598 |
-
}
|
599 |
-
|
600 |
-
$this->defaults[SF_FPRE.$key] = $taxs;
|
601 |
-
}
|
602 |
-
}
|
603 |
-
}
|
604 |
-
|
605 |
-
$post_date = array("","");
|
606 |
-
if(isset($wp_query->query['post_date']))
|
607 |
-
{
|
608 |
-
$post_date = explode("+", esc_attr(urlencode($wp_query->query['post_date'])));
|
609 |
-
if(count($post_date)==1)
|
610 |
-
{
|
611 |
-
$post_date[1] = "";
|
612 |
-
}
|
613 |
-
}
|
614 |
-
$this->defaults[SF_FPRE.'post_date'] = $post_date;
|
615 |
-
|
616 |
-
|
617 |
-
$post_types = array();
|
618 |
-
if(isset($wp_query->query['post_types']))
|
619 |
-
{
|
620 |
-
$post_types = explode(",",esc_attr($wp_query->query['post_types']));
|
621 |
-
}
|
622 |
-
$this->defaults[SF_FPRE.'post_types'] = $post_types;
|
623 |
-
|
624 |
-
}
|
625 |
-
|
626 |
-
/*
|
627 |
-
* check to see if form has been submitted and handle vars
|
628 |
-
*/
|
629 |
-
|
630 |
-
public function check_posts()
|
631 |
-
{
|
632 |
-
if(isset($_POST[SF_FPRE.'submitted']))
|
633 |
-
{
|
634 |
-
if($_POST[SF_FPRE.'submitted']==="1")
|
635 |
-
{
|
636 |
-
//set var to confirm the form was posted
|
637 |
-
$this->has_form_posted = true;
|
638 |
-
}
|
639 |
-
}
|
640 |
-
|
641 |
-
/* CATEGORIES */
|
642 |
-
if((isset($_POST[SF_FPRE.'category']))&&($this->has_form_posted))
|
643 |
-
{
|
644 |
-
$the_post_cat = ($_POST[SF_FPRE.'category']);
|
645 |
-
|
646 |
-
//make the post an array for easy looping
|
647 |
-
if(!is_array($_POST[SF_FPRE.'category']))
|
648 |
-
{
|
649 |
-
$post_cat[] = $the_post_cat;
|
650 |
-
}
|
651 |
-
else
|
652 |
-
{
|
653 |
-
$post_cat = $the_post_cat;
|
654 |
-
}
|
655 |
-
$catarr = array();
|
656 |
-
|
657 |
-
foreach ($post_cat as $cat)
|
658 |
-
{
|
659 |
-
$cat = esc_attr($cat);
|
660 |
-
$catobj = get_category($cat);
|
661 |
-
|
662 |
-
if(isset($catobj->slug))
|
663 |
-
{
|
664 |
-
$catarr[] = $catobj->slug;
|
665 |
-
//$catarr[] = $catobj->term_id;
|
666 |
-
}
|
667 |
-
}
|
668 |
-
|
669 |
-
if(count($catarr)>0)
|
670 |
-
{
|
671 |
-
$operator = "+"; //default behaviour
|
672 |
-
|
673 |
-
//check to see if an operator has been specified - only applies with fields that use multiple selects such as checkboxes or multi selects
|
674 |
-
if(isset($_POST[SF_FPRE.'category_operator']))
|
675 |
-
{
|
676 |
-
if($_POST[SF_FPRE.'category_operator']=="and")
|
677 |
-
{
|
678 |
-
$operator = "+";
|
679 |
-
}
|
680 |
-
else if($_POST[SF_FPRE.'category_operator']=="or")
|
681 |
-
{
|
682 |
-
$operator = ",";
|
683 |
-
}
|
684 |
-
else
|
685 |
-
{
|
686 |
-
$operator = "+";
|
687 |
-
}
|
688 |
-
}
|
689 |
-
|
690 |
-
$categories = implode($operator,$catarr);
|
691 |
-
|
692 |
-
if(get_option('permalink_structure'))
|
693 |
-
{
|
694 |
-
//$catrel = trim(str_replace(home_url(), "", get_category_link()), "/").$categories."/"; //get full category link, remvoe the home url to get relative, trim traling slashed, the append slash at the end
|
695 |
-
$category_base = (get_option( 'category_base' )=="") ? "category" : get_option( 'category_base' );
|
696 |
-
$category_path = $category_base."/".$categories."/";
|
697 |
-
$this->urlparams .= $category_path;
|
698 |
-
}
|
699 |
-
else
|
700 |
-
{
|
701 |
-
if(!$this->hasqmark)
|
702 |
-
{
|
703 |
-
$this->urlparams .= "?";
|
704 |
-
$this->hasqmark = true;
|
705 |
-
}
|
706 |
-
else
|
707 |
-
{
|
708 |
-
$this->urlparams .= "&";
|
709 |
-
}
|
710 |
-
$this->urlparams .= "category_name=".$categories;
|
711 |
-
}
|
712 |
-
}
|
713 |
-
}
|
714 |
-
|
715 |
-
/* SEARCH BOX */
|
716 |
-
if((isset($_POST[SF_FPRE.'search']))&&($this->has_form_posted))
|
717 |
-
{
|
718 |
-
$this->searchterm = trim(stripslashes($_POST[SF_FPRE.'search']));
|
719 |
-
|
720 |
-
if($this->searchterm!="")
|
721 |
-
{
|
722 |
-
if(!$this->hasqmark)
|
723 |
-
{
|
724 |
-
$this->urlparams .= "?";
|
725 |
-
$this->hasqmark = true;
|
726 |
-
}
|
727 |
-
else
|
728 |
-
{
|
729 |
-
$this->urlparams .= "&";
|
730 |
-
}
|
731 |
-
$this->urlparams .= "s=".urlencode($this->searchterm);
|
732 |
-
$this->hassearchquery = true;
|
733 |
-
}
|
734 |
-
}
|
735 |
-
if(!$this->hassearchquery)
|
736 |
-
{
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
{
|
984 |
-
$
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
$
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
$
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
$
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
if($
|
1219 |
-
{
|
1220 |
-
$tempobject = array();
|
1221 |
-
$tempobject['term_id'] = $post_type;
|
1222 |
-
$tempobject['cat_name'] = $
|
1223 |
-
|
1224 |
-
$taxonomychildren[] = (object)$tempobject;
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
$
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
}
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
$
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
}
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
$args['
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
$returnvar .= $this->
|
1371 |
-
}
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
$
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
$
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
$
|
1415 |
-
}
|
1416 |
-
}
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
$returnvar
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
}
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
$returnvar
|
1465 |
-
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
-
|
1472 |
-
|
1473 |
-
|
1474 |
-
$returnvar
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
-
|
1480 |
-
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
1516 |
-
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
if(isset($this->defaults[SF_FPRE.$name]))
|
1526 |
-
{
|
1527 |
-
$defaults = $this->defaults[SF_FPRE.$name];
|
1528 |
-
|
1529 |
-
$noselected = count($defaults);
|
1530 |
-
|
1531 |
-
if(($noselected
|
1532 |
-
{
|
1533 |
-
foreach($defaults as $defaultid)
|
1534 |
-
{
|
1535 |
-
if($defaultid==$dropdown->term_id)
|
1536 |
-
{
|
1537 |
-
$
|
1538 |
-
}
|
1539 |
-
}
|
1540 |
-
}
|
1541 |
-
}
|
1542 |
-
$returnvar .= '<
|
1543 |
-
|
1544 |
-
}
|
1545 |
-
|
1546 |
-
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
-
|
1552 |
-
|
1553 |
-
|
1554 |
-
$
|
1555 |
-
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
1559 |
-
if(isset($this->defaults[SF_FPRE.$name]))
|
1560 |
-
{
|
1561 |
-
$defaults = $this->defaults[SF_FPRE.$name];
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
1565 |
-
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
|
1570 |
-
|
1571 |
-
|
1572 |
-
|
1573 |
-
}
|
1574 |
-
}
|
1575 |
-
}
|
1576 |
-
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
-
|
1584 |
-
|
1585 |
-
|
1586 |
-
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
$
|
1613 |
-
|
1614 |
-
|
1615 |
-
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
$
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
1634 |
-
|
1635 |
-
|
1636 |
-
|
1637 |
-
$
|
1638 |
-
|
1639 |
-
|
1640 |
-
|
1641 |
-
|
1642 |
-
$
|
1643 |
-
|
1644 |
-
|
1645 |
-
|
1646 |
-
|
1647 |
-
|
1648 |
-
$
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
-
}
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
1664 |
-
|
1665 |
-
|
1666 |
-
|
1667 |
-
|
1668 |
-
|
1669 |
-
|
1670 |
-
|
1671 |
-
|
1672 |
-
|
1673 |
-
|
1674 |
-
|
1675 |
-
|
1676 |
-
|
1677 |
-
|
1678 |
-
|
1679 |
-
|
1680 |
-
|
1681 |
-
|
1682 |
-
|
1683 |
-
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
1687 |
-
|
1688 |
-
|
1689 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1690 |
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Search & Filter
|
4 |
+
Plugin URI: http://www.designsandcode.com/447/wordpress-search-filter-plugin-for-taxonomies/
|
5 |
+
Description: Search and Filtering system for Pages, Posts, Categories, Tags and Taxonomies
|
6 |
+
Author: Designs & Code
|
7 |
+
Author URI: http://www.designsandcode.com/
|
8 |
+
Version: 1.2.5
|
9 |
+
Text Domain: searchandfilter
|
10 |
+
License: GPLv2
|
11 |
+
*/
|
12 |
+
|
13 |
+
// TO DO - i18n http://codex.wordpress.org/I18n_for_WordPress_Developers
|
14 |
+
|
15 |
+
/*
|
16 |
+
* Set up Plugin Globals
|
17 |
+
*/
|
18 |
+
if (!defined('SEARCHANDFILTER_VERSION_NUM'))
|
19 |
+
define('SEARCHANDFILTER_VERSION_NUM', '1.2.5');
|
20 |
+
|
21 |
+
if (!defined('SEARCHANDFILTER_THEME_DIR'))
|
22 |
+
define('SEARCHANDFILTER_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
|
23 |
+
|
24 |
+
if (!defined('SEARCHANDFILTER_PLUGIN_NAME'))
|
25 |
+
define('SEARCHANDFILTER_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
|
26 |
+
|
27 |
+
if (!defined('SEARCHANDFILTER_PLUGIN_DIR'))
|
28 |
+
define('SEARCHANDFILTER_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . SEARCHANDFILTER_PLUGIN_NAME);
|
29 |
+
|
30 |
+
if (!defined('SEARCHANDFILTER_PLUGIN_URL'))
|
31 |
+
define('SEARCHANDFILTER_PLUGIN_URL', WP_PLUGIN_URL . '/' . SEARCHANDFILTER_PLUGIN_NAME);
|
32 |
+
|
33 |
+
if (!defined('SEARCHANDFILTER_BASENAME'))
|
34 |
+
define('SEARCHANDFILTER_BASENAME', plugin_basename(__FILE__));
|
35 |
+
|
36 |
+
if (!defined('SEARCHANDFILTER_VERSION_KEY'))
|
37 |
+
define('SEARCHANDFILTER_VERSION_KEY', 'searchandfilter_version');
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
//form prefix for plugin
|
42 |
+
if (!defined('SF_FPRE'))
|
43 |
+
define('SF_FPRE', 'of');
|
44 |
+
|
45 |
+
add_option(SEARCHANDFILTER_VERSION_KEY, SEARCHANDFILTER_VERSION_NUM);
|
46 |
+
|
47 |
+
/*
|
48 |
+
* Set up Plugin Globals
|
49 |
+
*/
|
50 |
+
if ( ! class_exists( 'SearchAndFilter' ) )
|
51 |
+
{
|
52 |
+
class SearchAndFilter
|
53 |
+
{
|
54 |
+
private $has_form_posted = false;
|
55 |
+
private $hasqmark = false;
|
56 |
+
private $hassearchquery = false;
|
57 |
+
private $urlparams = "/";
|
58 |
+
private $searchterm = "";
|
59 |
+
private $tagid = 0;
|
60 |
+
private $catid = 0;
|
61 |
+
private $defaults = array();
|
62 |
+
private $frmreserved = array();
|
63 |
+
private $taxonomylist = array();
|
64 |
+
|
65 |
+
public function __construct()
|
66 |
+
{
|
67 |
+
|
68 |
+
// Set up reserved fields
|
69 |
+
$this->frmreserved = array(SF_FPRE."category", SF_FPRE."search", SF_FPRE."post_tag", SF_FPRE."submitted", SF_FPRE."post_date", SF_FPRE."post_types");
|
70 |
+
$this->frmqreserved = array(SF_FPRE."category_name", SF_FPRE."s", SF_FPRE."tag", SF_FPRE."submitted", SF_FPRE."post_date", SF_FPRE."post_types"); //same as reserved
|
71 |
+
|
72 |
+
//add query vars
|
73 |
+
add_filter('query_vars', array($this,'add_queryvars') );
|
74 |
+
|
75 |
+
//filter post type & date if it is set
|
76 |
+
add_filter('pre_get_posts', array($this,'filter_query_post_types'));
|
77 |
+
add_filter('pre_get_posts', array($this,'filter_query_post_date'));
|
78 |
+
|
79 |
+
//add_filter('pre_get_posts',array($this, 'fix_blank_search')); //temporaril disabled
|
80 |
+
|
81 |
+
// Add shortcode support for widgets
|
82 |
+
add_shortcode('searchandfilter', array($this, 'shortcode'));
|
83 |
+
add_filter('widget_text', 'do_shortcode');
|
84 |
+
|
85 |
+
// Check the header to see if the form has been submitted
|
86 |
+
add_action( 'get_header', array( $this, 'check_posts' ) );
|
87 |
+
|
88 |
+
// Add styles
|
89 |
+
add_action( 'wp_enqueue_scripts', array($this, 'of_enqueue_styles') );
|
90 |
+
add_action( 'admin_enqueue_scripts', array($this, 'of_enqueue_admin_ss') );
|
91 |
+
|
92 |
+
}
|
93 |
+
|
94 |
+
public function of_enqueue_styles()
|
95 |
+
{
|
96 |
+
wp_enqueue_style( 'searchandfilter', SEARCHANDFILTER_PLUGIN_URL . '/style.css', false, 1.0, 'all' );
|
97 |
+
}
|
98 |
+
public function of_enqueue_admin_ss($hook)
|
99 |
+
{
|
100 |
+
if( 'toplevel_page_searchandfilter-settings' == $hook )
|
101 |
+
{
|
102 |
+
wp_enqueue_style( 'of_syntax_style', SEARCHANDFILTER_PLUGIN_URL.'/admin/github.css', false, 1.0, 'all' ); //more highlight styles http://softwaremaniacs.org/media/soft/highlight/test.html
|
103 |
+
wp_enqueue_style( 'of_style', SEARCHANDFILTER_PLUGIN_URL.'/admin/style.css', false, 1.0, 'all' );
|
104 |
+
wp_enqueue_script( 'of_syntax_script', SEARCHANDFILTER_PLUGIN_URL.'/admin/syntax.highlight.min.js' );
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
public function shortcode($atts, $content = null)
|
109 |
+
{
|
110 |
+
// extract the attributes into variables
|
111 |
+
extract(shortcode_atts(array(
|
112 |
+
|
113 |
+
'fields' => null,
|
114 |
+
'taxonomies' => null, //will be deprecated - use `fields` instead
|
115 |
+
'submit_label' => null,
|
116 |
+
'submitlabel' => null, //will be deprecated - use `submit_label` instead
|
117 |
+
'search_placeholder' => "Search …",
|
118 |
+
'types' => "",
|
119 |
+
'type' => "", //will be deprecated - use `types` instead
|
120 |
+
'headings' => "",
|
121 |
+
'all_items_labels' => "",
|
122 |
+
'class' => "",
|
123 |
+
'post_types' => "",
|
124 |
+
'hierarchical' => "",
|
125 |
+
'hide_empty' => "",
|
126 |
+
'order_by' => "",
|
127 |
+
'show_count' => "",
|
128 |
+
'order_dir' => "",
|
129 |
+
'operators' => "",
|
130 |
+
'add_search_param' => "0",
|
131 |
+
'empty_search_url' => ""
|
132 |
+
|
133 |
+
), $atts));
|
134 |
+
|
135 |
+
//init `fields`
|
136 |
+
if($fields!=null)
|
137 |
+
{
|
138 |
+
$fields = explode(",",$fields);
|
139 |
+
}
|
140 |
+
else
|
141 |
+
{
|
142 |
+
$fields = explode(",",$taxonomies);
|
143 |
+
}
|
144 |
+
|
145 |
+
$this->taxonomylist = $fields;
|
146 |
+
$nofields = count($fields);
|
147 |
+
|
148 |
+
$add_search_param = (int)$add_search_param;
|
149 |
+
|
150 |
+
|
151 |
+
//init `submitlabel`
|
152 |
+
if($submitlabel!=null)
|
153 |
+
{//then the old "submitlabel" has been supplied
|
154 |
+
|
155 |
+
if($submit_label==null)
|
156 |
+
{
|
157 |
+
//then the new label has not been supplied so do nothing
|
158 |
+
$submit_label = $submitlabel;
|
159 |
+
}
|
160 |
+
else
|
161 |
+
{
|
162 |
+
//then the new label has been supplied so take the new label value
|
163 |
+
//$submit_label = $submit_label;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
else if($submitlabel==null)
|
167 |
+
{
|
168 |
+
if($submit_label==null)
|
169 |
+
{//default value
|
170 |
+
$submit_label = "Submit";
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
//init `post_types`
|
175 |
+
if($post_types!="")
|
176 |
+
{
|
177 |
+
$post_types = explode(",",$post_types);
|
178 |
+
}
|
179 |
+
else
|
180 |
+
{
|
181 |
+
if(in_array("post_types", $fields))
|
182 |
+
{
|
183 |
+
$post_types = array("all");
|
184 |
+
}
|
185 |
+
|
186 |
+
}
|
187 |
+
|
188 |
+
//init `hierarchical`
|
189 |
+
if($hierarchical!="")
|
190 |
+
{
|
191 |
+
$hierarchical = explode(",",$hierarchical);
|
192 |
+
}
|
193 |
+
else
|
194 |
+
{
|
195 |
+
$hierarchical = array("");
|
196 |
+
}
|
197 |
+
|
198 |
+
//init `hide_empty`
|
199 |
+
if($hide_empty!="")
|
200 |
+
{
|
201 |
+
$hide_empty = explode(",",$hide_empty);
|
202 |
+
}
|
203 |
+
else
|
204 |
+
{
|
205 |
+
$hide_empty = array("");
|
206 |
+
}
|
207 |
+
|
208 |
+
//init `show_count`
|
209 |
+
if($show_count!="")
|
210 |
+
{
|
211 |
+
$show_count = explode(",",$show_count);
|
212 |
+
}
|
213 |
+
else
|
214 |
+
{
|
215 |
+
$show_count = array();
|
216 |
+
}
|
217 |
+
|
218 |
+
//init `order_by`
|
219 |
+
if($order_by!="")
|
220 |
+
{
|
221 |
+
$order_by = explode(",",$order_by);
|
222 |
+
}
|
223 |
+
else
|
224 |
+
{
|
225 |
+
$order_by = array("");
|
226 |
+
}
|
227 |
+
|
228 |
+
//init `order_dir`
|
229 |
+
if($order_dir!="")
|
230 |
+
{
|
231 |
+
$order_dir = explode(",",$order_dir);
|
232 |
+
}
|
233 |
+
else
|
234 |
+
{
|
235 |
+
$order_dir = array("");
|
236 |
+
}
|
237 |
+
|
238 |
+
//init `operators`
|
239 |
+
if($operators!="")
|
240 |
+
{
|
241 |
+
$operators = explode(",",$operators);
|
242 |
+
}
|
243 |
+
else
|
244 |
+
{
|
245 |
+
$operators = array("");
|
246 |
+
}
|
247 |
+
|
248 |
+
|
249 |
+
//init `labels`
|
250 |
+
$labels = explode(",",$headings);
|
251 |
+
|
252 |
+
if(!is_array($labels))
|
253 |
+
{
|
254 |
+
$labels = array();
|
255 |
+
}
|
256 |
+
|
257 |
+
//init `all_items_labels`
|
258 |
+
$all_items_labels = explode(",",$all_items_labels);
|
259 |
+
|
260 |
+
if(!is_array($all_items_labels))
|
261 |
+
{
|
262 |
+
$all_items_labels = array();
|
263 |
+
}
|
264 |
+
|
265 |
+
//init `types`
|
266 |
+
if($types!=null)
|
267 |
+
{
|
268 |
+
$types = explode(",",$types);
|
269 |
+
}
|
270 |
+
else
|
271 |
+
{
|
272 |
+
$types = explode(",",$type);
|
273 |
+
}
|
274 |
+
|
275 |
+
if(!is_array($types))
|
276 |
+
{
|
277 |
+
$types = array();
|
278 |
+
}
|
279 |
+
|
280 |
+
//init empty_search_url
|
281 |
+
|
282 |
+
|
283 |
+
//Loop through Fields and set up default vars
|
284 |
+
for($i=0; $i<$nofields; $i++)
|
285 |
+
{//loop through all fields
|
286 |
+
|
287 |
+
//set up types
|
288 |
+
if(isset($types[$i]))
|
289 |
+
{
|
290 |
+
if($fields[$i] == 'post_date')
|
291 |
+
{//check for post date field
|
292 |
+
|
293 |
+
if(($types[$i]!="date")&&($types[$i]!="daterange"))
|
294 |
+
{//if not expected value
|
295 |
+
|
296 |
+
$types[$i] = "date"; //use default
|
297 |
+
}
|
298 |
+
}
|
299 |
+
else
|
300 |
+
{//everything else can use a standard form input - checkbox/radio/dropdown/list/multiselect
|
301 |
+
|
302 |
+
if(($types[$i]!="select")&&($types[$i]!="checkbox")&&($types[$i]!="radio")&&($types[$i]!="list")&&($types[$i]!="multiselect"))
|
303 |
+
{//no accepted type matched - non compatible type defined by user
|
304 |
+
|
305 |
+
$types[$i] = "select"; //use default
|
306 |
+
}
|
307 |
+
}
|
308 |
+
}
|
309 |
+
else
|
310 |
+
{//omitted, so set default
|
311 |
+
|
312 |
+
if($fields[$i] == 'post_date')
|
313 |
+
{
|
314 |
+
$types[$i] = "date";
|
315 |
+
}
|
316 |
+
else
|
317 |
+
{
|
318 |
+
$types[$i] = "select";
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
//setup labels
|
323 |
+
if(!isset($labels[$i]))
|
324 |
+
{
|
325 |
+
$labels[$i] = "";
|
326 |
+
}
|
327 |
+
|
328 |
+
//setup all_items_labels
|
329 |
+
if(!isset($all_items_labels[$i]))
|
330 |
+
{
|
331 |
+
$all_items_labels[$i] = "";
|
332 |
+
}
|
333 |
+
|
334 |
+
|
335 |
+
if(isset($order_by[$i]))
|
336 |
+
{
|
337 |
+
if(($order_by[$i]!="id")&&($order_by[$i]!="name")&&($order_by[$i]!="slug")&&($order_by[$i]!="count")&&($order_by[$i]!="term_group"))
|
338 |
+
{
|
339 |
+
$order_by[$i] = "name"; //use default - possible typo or use of unknown value
|
340 |
+
}
|
341 |
+
}
|
342 |
+
else
|
343 |
+
{
|
344 |
+
$order_by[$i] = "name"; //use default
|
345 |
+
}
|
346 |
+
|
347 |
+
if(isset($order_dir[$i]))
|
348 |
+
{
|
349 |
+
if(($order_dir[$i]!="asc")&&($order_dir[$i]!="desc"))
|
350 |
+
{//then order_dir is not a wanted value
|
351 |
+
|
352 |
+
$order_dir[$i] = "asc"; //set to default
|
353 |
+
}
|
354 |
+
}
|
355 |
+
else
|
356 |
+
{
|
357 |
+
$order_dir[$i] = "asc"; //use default
|
358 |
+
}
|
359 |
+
|
360 |
+
if(isset($operators[$i]))
|
361 |
+
{
|
362 |
+
if(($operators[$i]!="and")&&($operators[$i]!="or"))
|
363 |
+
{
|
364 |
+
$operators[$i] = "and"; //else use default - possible typo or use of unknown value
|
365 |
+
}
|
366 |
+
}
|
367 |
+
else
|
368 |
+
{
|
369 |
+
$operators[$i] = "and"; //use default
|
370 |
+
}
|
371 |
+
|
372 |
+
}
|
373 |
+
|
374 |
+
//set all form defaults / dropdowns etc
|
375 |
+
$this->set_defaults();
|
376 |
+
|
377 |
+
return $this->get_search_filter_form($submit_label, $search_placeholder, $fields, $types, $labels, $hierarchical, $hide_empty, $show_count, $post_types, $order_by, $order_dir, $operators, $all_items_labels, $empty_search_url, $add_search_param, $class);
|
378 |
+
}
|
379 |
+
|
380 |
+
|
381 |
+
function add_queryvars( $qvars )
|
382 |
+
{
|
383 |
+
$qvars[] = 'post_types';
|
384 |
+
$qvars[] = 'post_date';
|
385 |
+
return $qvars;
|
386 |
+
}
|
387 |
+
|
388 |
+
function filter_query_post_types($query)
|
389 |
+
{
|
390 |
+
global $wp_query;
|
391 |
+
|
392 |
+
if(($query->is_main_query())&&(!is_admin()))
|
393 |
+
{
|
394 |
+
if(isset($wp_query->query['post_types']))
|
395 |
+
{
|
396 |
+
$search_all = false;
|
397 |
+
|
398 |
+
$post_types = explode(",",esc_attr($wp_query->query['post_types']));
|
399 |
+
if(isset($post_types[0]))
|
400 |
+
{
|
401 |
+
if(count($post_types)==1)
|
402 |
+
{
|
403 |
+
if($post_types[0]=="all")
|
404 |
+
{
|
405 |
+
$search_all = true;
|
406 |
+
}
|
407 |
+
}
|
408 |
+
}
|
409 |
+
if($search_all)
|
410 |
+
{
|
411 |
+
$post_types = get_post_types( '', 'names' );
|
412 |
+
$query->set('post_type', $post_types); //here we set the post types that we want WP to search
|
413 |
+
}
|
414 |
+
else
|
415 |
+
{
|
416 |
+
$query->set('post_type', $post_types); //here we set the post types that we want WP to search
|
417 |
+
}
|
418 |
+
}
|
419 |
+
}
|
420 |
+
|
421 |
+
return $query;
|
422 |
+
}
|
423 |
+
|
424 |
+
|
425 |
+
function limit_date_range_query( $where )
|
426 |
+
{
|
427 |
+
global $wp_query;
|
428 |
+
|
429 |
+
//get post dates into array
|
430 |
+
$post_date = explode("+", esc_attr(urlencode($wp_query->query['post_date'])));
|
431 |
+
|
432 |
+
if (count($post_date) > 1 && $post_date[0] != $post_date[1])
|
433 |
+
{
|
434 |
+
$date_query = array();
|
435 |
+
|
436 |
+
if (!empty($post_date[0]))
|
437 |
+
{
|
438 |
+
$date_query['after'] = date('Y-m-d 00:00:00', strtotime($post_date[0]));
|
439 |
+
}
|
440 |
+
|
441 |
+
if (!empty($post_date[1]))
|
442 |
+
{
|
443 |
+
$date_query['before'] = date('Y-m-d 23:59:59', strtotime($post_date[1]));
|
444 |
+
}
|
445 |
+
|
446 |
+
}
|
447 |
+
|
448 |
+
// Append fragment to WHERE clause to select posts newer than the past week.
|
449 |
+
$where .= " AND post_date >='" . $date_query['after'] . "' AND post_date <='" . $date_query['before'] . "'";
|
450 |
+
|
451 |
+
return $where;
|
452 |
+
}
|
453 |
+
|
454 |
+
/**
|
455 |
+
* Remove the filter limiting posts to the past week.
|
456 |
+
*
|
457 |
+
* Remove the filter after it runs so that it doesn't affect any other
|
458 |
+
* queries that might be performed on the same page (eg. Recent Posts
|
459 |
+
* widget).
|
460 |
+
*/
|
461 |
+
function remove_limit_date_range_query()
|
462 |
+
{
|
463 |
+
remove_filter( 'posts_where', 'limit_date_range_query' );
|
464 |
+
}
|
465 |
+
|
466 |
+
function fix_blank_search($query)
|
467 |
+
{//needs to be re-implemented
|
468 |
+
|
469 |
+
if((isset($_GET['s'])) && (empty($_GET['s'])) && ($query->is_main_query()))
|
470 |
+
{
|
471 |
+
$query->is_search = true;
|
472 |
+
$query->is_home = false;
|
473 |
+
}
|
474 |
+
|
475 |
+
}
|
476 |
+
|
477 |
+
function filter_query_post_date($query)
|
478 |
+
{
|
479 |
+
global $wp_query;
|
480 |
+
|
481 |
+
if(($query->is_main_query())&&(!is_admin()))
|
482 |
+
{
|
483 |
+
if(isset($wp_query->query['post_date']))
|
484 |
+
{
|
485 |
+
//get post dates into array
|
486 |
+
$post_date = explode("+", esc_attr(urlencode($wp_query->query['post_date'])));
|
487 |
+
|
488 |
+
if(!empty($post_date))
|
489 |
+
{
|
490 |
+
//if there is more than 1 post date and the dates are not the same
|
491 |
+
if (count($post_date) > 1 && $post_date[0] != $post_date[1])
|
492 |
+
{
|
493 |
+
if((!empty($post_date[0]))&&(!empty($post_date[1])))
|
494 |
+
{
|
495 |
+
// Attach hook to filter WHERE clause.
|
496 |
+
add_filter('posts_where', array($this,'limit_date_range_query'));
|
497 |
+
|
498 |
+
// Remove the filter after it is executed.
|
499 |
+
add_action('posts_selection', array($this,'remove_limit_date_range_query'));
|
500 |
+
}
|
501 |
+
}
|
502 |
+
else
|
503 |
+
{ //else we are dealing with one date or both dates are the same (so need to find posts for a single day)
|
504 |
+
|
505 |
+
if (!empty($post_date[0]))
|
506 |
+
{
|
507 |
+
$post_time = strtotime($post_date[0]);
|
508 |
+
$query->set('year', date('Y', $post_time));
|
509 |
+
$query->set('monthnum', date('m', $post_time));
|
510 |
+
$query->set('day', date('d', $post_time));
|
511 |
+
}
|
512 |
+
}
|
513 |
+
}
|
514 |
+
}
|
515 |
+
}
|
516 |
+
|
517 |
+
return $query;
|
518 |
+
}
|
519 |
+
|
520 |
+
/*
|
521 |
+
* check to set defaults - to be called after the shortcodes have been init so we can grab the wanted list of fields
|
522 |
+
*/
|
523 |
+
public function set_defaults()
|
524 |
+
{
|
525 |
+
global $wp_query;
|
526 |
+
|
527 |
+
$categories = array();
|
528 |
+
|
529 |
+
if(isset($wp_query->query['category_name']))
|
530 |
+
{
|
531 |
+
$category_params = (preg_split("/[,\+ ]/", esc_attr($wp_query->query['category_name']))); //explode with 2 delims
|
532 |
+
|
533 |
+
//$category_params = explode("+",esc_attr($wp_query->query['category_name']));
|
534 |
+
|
535 |
+
foreach($category_params as $category_param)
|
536 |
+
{
|
537 |
+
$category = get_category_by_slug( $category_param );
|
538 |
+
if(isset($category->cat_ID))
|
539 |
+
{
|
540 |
+
$categories[] = $category->cat_ID;
|
541 |
+
}
|
542 |
+
}
|
543 |
+
}
|
544 |
+
|
545 |
+
$this->defaults[SF_FPRE.'category'] = $categories;
|
546 |
+
|
547 |
+
|
548 |
+
//grab search term for prefilling search input
|
549 |
+
if(isset($wp_query->query['s']))
|
550 |
+
{//!"�$%^&*()
|
551 |
+
$this->searchterm = trim(get_search_query());
|
552 |
+
}
|
553 |
+
|
554 |
+
//check to see if tag is set
|
555 |
+
|
556 |
+
$tags = array();
|
557 |
+
|
558 |
+
if(isset($wp_query->query['tag']))
|
559 |
+
{
|
560 |
+
$tag_params = (preg_split("/[,\+ ]/", esc_attr($wp_query->query['tag']))); //explode with 2 delims
|
561 |
+
//$tag_params = explode("+",esc_attr($wp_query->query['tag']));
|
562 |
+
|
563 |
+
foreach($tag_params as $tag_param)
|
564 |
+
{
|
565 |
+
$tag = get_term_by("slug",$tag_param, "post_tag");
|
566 |
+
if(isset($tag->term_id))
|
567 |
+
{
|
568 |
+
$tags[] = $tag->term_id;
|
569 |
+
}
|
570 |
+
}
|
571 |
+
}
|
572 |
+
|
573 |
+
$this->defaults[SF_FPRE.'post_tag'] = $tags;
|
574 |
+
|
575 |
+
$taxs = array();
|
576 |
+
//loop through all the query vars
|
577 |
+
foreach($wp_query->query as $key=>$val)
|
578 |
+
{
|
579 |
+
if(!in_array(SF_FPRE.$key, $this->frmqreserved))
|
580 |
+
{//make sure the get is not a reserved get as they have already been handled above
|
581 |
+
|
582 |
+
//now check it is a desired key
|
583 |
+
if(in_array($key, $this->taxonomylist))
|
584 |
+
{
|
585 |
+
$taxslug = ($val);
|
586 |
+
//$tax_params = explode("+",esc_attr($taxslug));
|
587 |
+
|
588 |
+
$tax_params = (preg_split("/[,\+ ]/", esc_attr($taxslug))); //explode with 2 delims
|
589 |
+
|
590 |
+
foreach($tax_params as $tax_param)
|
591 |
+
{
|
592 |
+
$tax = get_term_by("slug",$tax_param, $key);
|
593 |
+
|
594 |
+
if(isset($tax->term_id))
|
595 |
+
{
|
596 |
+
$taxs[] = $tax->term_id;
|
597 |
+
}
|
598 |
+
}
|
599 |
+
|
600 |
+
$this->defaults[SF_FPRE.$key] = $taxs;
|
601 |
+
}
|
602 |
+
}
|
603 |
+
}
|
604 |
+
|
605 |
+
$post_date = array("","");
|
606 |
+
if(isset($wp_query->query['post_date']))
|
607 |
+
{
|
608 |
+
$post_date = explode("+", esc_attr(urlencode($wp_query->query['post_date'])));
|
609 |
+
if(count($post_date)==1)
|
610 |
+
{
|
611 |
+
$post_date[1] = "";
|
612 |
+
}
|
613 |
+
}
|
614 |
+
$this->defaults[SF_FPRE.'post_date'] = $post_date;
|
615 |
+
|
616 |
+
|
617 |
+
$post_types = array();
|
618 |
+
if(isset($wp_query->query['post_types']))
|
619 |
+
{
|
620 |
+
$post_types = explode(",",esc_attr($wp_query->query['post_types']));
|
621 |
+
}
|
622 |
+
$this->defaults[SF_FPRE.'post_types'] = $post_types;
|
623 |
+
|
624 |
+
}
|
625 |
+
|
626 |
+
/*
|
627 |
+
* check to see if form has been submitted and handle vars
|
628 |
+
*/
|
629 |
+
|
630 |
+
public function check_posts()
|
631 |
+
{
|
632 |
+
if(isset($_POST[SF_FPRE.'submitted']))
|
633 |
+
{
|
634 |
+
if($_POST[SF_FPRE.'submitted']==="1")
|
635 |
+
{
|
636 |
+
//set var to confirm the form was posted
|
637 |
+
$this->has_form_posted = true;
|
638 |
+
}
|
639 |
+
}
|
640 |
+
|
641 |
+
/* CATEGORIES */
|
642 |
+
if((isset($_POST[SF_FPRE.'category']))&&($this->has_form_posted))
|
643 |
+
{
|
644 |
+
$the_post_cat = ($_POST[SF_FPRE.'category']);
|
645 |
+
|
646 |
+
//make the post an array for easy looping
|
647 |
+
if(!is_array($_POST[SF_FPRE.'category']))
|
648 |
+
{
|
649 |
+
$post_cat[] = $the_post_cat;
|
650 |
+
}
|
651 |
+
else
|
652 |
+
{
|
653 |
+
$post_cat = $the_post_cat;
|
654 |
+
}
|
655 |
+
$catarr = array();
|
656 |
+
|
657 |
+
foreach ($post_cat as $cat)
|
658 |
+
{
|
659 |
+
$cat = esc_attr($cat);
|
660 |
+
$catobj = get_category($cat);
|
661 |
+
|
662 |
+
if(isset($catobj->slug))
|
663 |
+
{
|
664 |
+
$catarr[] = $catobj->slug;
|
665 |
+
//$catarr[] = $catobj->term_id;
|
666 |
+
}
|
667 |
+
}
|
668 |
+
|
669 |
+
if(count($catarr)>0)
|
670 |
+
{
|
671 |
+
$operator = "+"; //default behaviour
|
672 |
+
|
673 |
+
//check to see if an operator has been specified - only applies with fields that use multiple selects such as checkboxes or multi selects
|
674 |
+
if(isset($_POST[SF_FPRE.'category_operator']))
|
675 |
+
{
|
676 |
+
if($_POST[SF_FPRE.'category_operator']=="and")
|
677 |
+
{
|
678 |
+
$operator = "+";
|
679 |
+
}
|
680 |
+
else if($_POST[SF_FPRE.'category_operator']=="or")
|
681 |
+
{
|
682 |
+
$operator = ",";
|
683 |
+
}
|
684 |
+
else
|
685 |
+
{
|
686 |
+
$operator = "+";
|
687 |
+
}
|
688 |
+
}
|
689 |
+
|
690 |
+
$categories = implode($operator,$catarr);
|
691 |
+
|
692 |
+
if(get_option('permalink_structure'))
|
693 |
+
{
|
694 |
+
//$catrel = trim(str_replace(home_url(), "", get_category_link()), "/").$categories."/"; //get full category link, remvoe the home url to get relative, trim traling slashed, the append slash at the end
|
695 |
+
$category_base = (get_option( 'category_base' )=="") ? "category" : get_option( 'category_base' );
|
696 |
+
$category_path = $category_base."/".$categories."/";
|
697 |
+
$this->urlparams .= $category_path;
|
698 |
+
}
|
699 |
+
else
|
700 |
+
{
|
701 |
+
if(!$this->hasqmark)
|
702 |
+
{
|
703 |
+
$this->urlparams .= "?";
|
704 |
+
$this->hasqmark = true;
|
705 |
+
}
|
706 |
+
else
|
707 |
+
{
|
708 |
+
$this->urlparams .= "&";
|
709 |
+
}
|
710 |
+
$this->urlparams .= "category_name=".$categories;
|
711 |
+
}
|
712 |
+
}
|
713 |
+
}
|
714 |
+
|
715 |
+
/* SEARCH BOX */
|
716 |
+
if((isset($_POST[SF_FPRE.'search']))&&($this->has_form_posted))
|
717 |
+
{
|
718 |
+
$this->searchterm = trim(stripslashes($_POST[SF_FPRE.'search']));
|
719 |
+
|
720 |
+
if($this->searchterm!="")
|
721 |
+
{
|
722 |
+
if(!$this->hasqmark)
|
723 |
+
{
|
724 |
+
$this->urlparams .= "?";
|
725 |
+
$this->hasqmark = true;
|
726 |
+
}
|
727 |
+
else
|
728 |
+
{
|
729 |
+
$this->urlparams .= "&";
|
730 |
+
}
|
731 |
+
$this->urlparams .= "s=".urlencode($this->searchterm);
|
732 |
+
$this->hassearchquery = true;
|
733 |
+
}
|
734 |
+
}
|
735 |
+
if(!$this->hassearchquery)
|
736 |
+
{
|
737 |
+
|
738 |
+
if((isset($_POST[SF_FPRE.'add_search_param']))&&($this->has_form_posted))
|
739 |
+
{//this is only set when a search box is displayed - it tells S&F to append a blank search to the URL to indicate a search has been submitted with no terms, however, still load the search template
|
740 |
+
|
741 |
+
|
742 |
+
|
743 |
+
if(!$this->hasqmark)
|
744 |
+
{
|
745 |
+
$this->urlparams .= "?";
|
746 |
+
$this->hasqmark = true;
|
747 |
+
}
|
748 |
+
else
|
749 |
+
{
|
750 |
+
$this->urlparams .= "&";
|
751 |
+
}
|
752 |
+
$this->urlparams .= "s=";
|
753 |
+
}
|
754 |
+
}
|
755 |
+
|
756 |
+
/* TAGS */
|
757 |
+
if((isset($_POST[SF_FPRE.'post_tag']))&&($this->has_form_posted))
|
758 |
+
{
|
759 |
+
$the_post_tag = ($_POST[SF_FPRE.'post_tag']);
|
760 |
+
|
761 |
+
//make the post an array for easy looping
|
762 |
+
if(!is_array($_POST[SF_FPRE.'post_tag']))
|
763 |
+
{
|
764 |
+
$post_tag[] = $the_post_tag;
|
765 |
+
}
|
766 |
+
else
|
767 |
+
{
|
768 |
+
$post_tag = $the_post_tag;
|
769 |
+
}
|
770 |
+
|
771 |
+
$tagarr = array();
|
772 |
+
|
773 |
+
foreach ($post_tag as $tag)
|
774 |
+
{
|
775 |
+
$tag = esc_attr($tag);
|
776 |
+
$tagobj = get_tag($tag);
|
777 |
+
|
778 |
+
if(isset($tagobj->slug))
|
779 |
+
{
|
780 |
+
$tagarr[] = $tagobj->slug;
|
781 |
+
}
|
782 |
+
}
|
783 |
+
|
784 |
+
if(count($tagarr)>0)
|
785 |
+
{
|
786 |
+
$operator = "+"; //default behaviour
|
787 |
+
|
788 |
+
//check to see if an operator has been specified - only applies with fields that use multiple selects such as checkboxes or multi selects
|
789 |
+
if(isset($_POST[SF_FPRE.'post_tag_operator']))
|
790 |
+
{
|
791 |
+
if($_POST[SF_FPRE.'post_tag_operator']=="and")
|
792 |
+
{
|
793 |
+
$operator = "+";
|
794 |
+
}
|
795 |
+
else if($_POST[SF_FPRE.'post_tag_operator']=="or")
|
796 |
+
{
|
797 |
+
$operator = ",";
|
798 |
+
}
|
799 |
+
else
|
800 |
+
{
|
801 |
+
$operator = "+";
|
802 |
+
}
|
803 |
+
}
|
804 |
+
|
805 |
+
$tags = implode($operator,$tagarr);
|
806 |
+
|
807 |
+
if(!$this->hasqmark)
|
808 |
+
{
|
809 |
+
$this->urlparams .= "?";
|
810 |
+
$this->hasqmark = true;
|
811 |
+
}
|
812 |
+
else
|
813 |
+
{
|
814 |
+
$this->urlparams .= "&";
|
815 |
+
}
|
816 |
+
$this->urlparams .= "tag=".$tags;
|
817 |
+
|
818 |
+
}
|
819 |
+
}
|
820 |
+
|
821 |
+
|
822 |
+
/* POST TYPES */
|
823 |
+
if((isset($_POST[SF_FPRE.'post_types']))&&($this->has_form_posted))
|
824 |
+
{
|
825 |
+
$the_post_types = ($_POST[SF_FPRE.'post_types']);
|
826 |
+
|
827 |
+
//make the post an array for easy looping
|
828 |
+
if(!is_array($the_post_types))
|
829 |
+
{
|
830 |
+
$post_types_arr[] = $the_post_types;
|
831 |
+
}
|
832 |
+
else
|
833 |
+
{
|
834 |
+
$post_types_arr = $the_post_types;
|
835 |
+
}
|
836 |
+
|
837 |
+
$num_post_types = count($post_types_arr);
|
838 |
+
|
839 |
+
for($i=0; $i<$num_post_types; $i++)
|
840 |
+
{
|
841 |
+
if($post_types_arr[$i]=="0")
|
842 |
+
{
|
843 |
+
$post_types_arr[$i] = "all";
|
844 |
+
}
|
845 |
+
}
|
846 |
+
|
847 |
+
if(count($post_types_arr)>0)
|
848 |
+
{
|
849 |
+
$operator = ","; //default behaviour
|
850 |
+
|
851 |
+
//check to see if an operator has been specified - only applies with fields that use multiple selects such as checkboxes or multi selects
|
852 |
+
/*if(isset($_POST[SF_FPRE.'post_types_operator']))
|
853 |
+
{
|
854 |
+
if($_POST[SF_FPRE.'post_types_operator']=="and")
|
855 |
+
{
|
856 |
+
$operator = "+";
|
857 |
+
}
|
858 |
+
else if($_POST[SF_FPRE.'post_types_operator']=="or")
|
859 |
+
{
|
860 |
+
$operator = ",";
|
861 |
+
}
|
862 |
+
else
|
863 |
+
{
|
864 |
+
$operator = "+";
|
865 |
+
}
|
866 |
+
}*/
|
867 |
+
|
868 |
+
$post_types = implode($operator,$post_types_arr);
|
869 |
+
|
870 |
+
if(!$this->hasqmark)
|
871 |
+
{
|
872 |
+
$this->urlparams .= "?";
|
873 |
+
$this->hasqmark = true;
|
874 |
+
}
|
875 |
+
else
|
876 |
+
{
|
877 |
+
$this->urlparams .= "&";
|
878 |
+
}
|
879 |
+
$this->urlparams .= "post_types=".$post_types;
|
880 |
+
|
881 |
+
}
|
882 |
+
}
|
883 |
+
|
884 |
+
|
885 |
+
/* POST DATE */
|
886 |
+
if((isset($_POST[SF_FPRE.'post_date']))&&($this->has_form_posted))
|
887 |
+
{
|
888 |
+
$the_post_date = ($_POST[SF_FPRE.'post_date']);
|
889 |
+
|
890 |
+
//make the post an array for easy looping
|
891 |
+
if(!is_array($the_post_date))
|
892 |
+
{
|
893 |
+
$post_date_arr[] = $the_post_date;
|
894 |
+
}
|
895 |
+
else
|
896 |
+
{
|
897 |
+
$post_date_arr = $the_post_date;
|
898 |
+
}
|
899 |
+
|
900 |
+
$num_post_date = count($post_date_arr);
|
901 |
+
|
902 |
+
for($i=0; $i<$num_post_date; $i++)
|
903 |
+
{
|
904 |
+
if($post_date_arr[$i]=="0")
|
905 |
+
{
|
906 |
+
$post_date_arr[$i] = "all";
|
907 |
+
}
|
908 |
+
}
|
909 |
+
|
910 |
+
if(count($post_date_arr)>0)
|
911 |
+
{
|
912 |
+
$post_date_count = count($post_date_arr);
|
913 |
+
|
914 |
+
if($post_date_count==2)
|
915 |
+
{//see if there are 2 elements in arr (second date range selector)
|
916 |
+
|
917 |
+
if(($post_date_arr[0]!="")&&($post_date_arr[1]==""))
|
918 |
+
{
|
919 |
+
$post_date = $post_date_arr[0];
|
920 |
+
}
|
921 |
+
else if($post_date_arr[1]=="")
|
922 |
+
{//if second date range is blank then remove the array element - this remove the addition of a '+' by implode below and only use first element
|
923 |
+
unset($post_date_arr[1]);
|
924 |
+
}
|
925 |
+
else if($post_date_arr[0]=="")
|
926 |
+
{
|
927 |
+
$post_date = "+".$post_date_arr[1];
|
928 |
+
}
|
929 |
+
else
|
930 |
+
{
|
931 |
+
$post_date = implode("+",array_filter($post_date_arr));
|
932 |
+
}
|
933 |
+
}
|
934 |
+
else
|
935 |
+
{
|
936 |
+
$post_date = $post_date_arr[0];
|
937 |
+
}
|
938 |
+
|
939 |
+
if(isset($post_date))
|
940 |
+
{
|
941 |
+
if($post_date!="")
|
942 |
+
{
|
943 |
+
if(!$this->hasqmark)
|
944 |
+
{
|
945 |
+
$this->urlparams .= "?";
|
946 |
+
$this->hasqmark = true;
|
947 |
+
}
|
948 |
+
else
|
949 |
+
{
|
950 |
+
$this->urlparams .= "&";
|
951 |
+
}
|
952 |
+
$this->urlparams .= "post_date=".$post_date;
|
953 |
+
}
|
954 |
+
}
|
955 |
+
}
|
956 |
+
}
|
957 |
+
|
958 |
+
|
959 |
+
//now we have dealt with the all the special case fields - search, tags, categories, post_types, post_date
|
960 |
+
|
961 |
+
//loop through the posts - double check that it is the search form that has been posted, otherwise we could be looping through the posts submitted from an entirely unrelated form
|
962 |
+
if($this->has_form_posted)
|
963 |
+
{
|
964 |
+
foreach($_POST as $key=>$val)
|
965 |
+
{
|
966 |
+
if(!in_array($key, $this->frmreserved))
|
967 |
+
{//if the key is not in the reserved array (ie, on a custom taxonomy - not tags, categories, search term, post type & post date)
|
968 |
+
|
969 |
+
// strip off all prefixes for custom fields - we just want to do a redirect - no processing
|
970 |
+
if (strpos($key, SF_FPRE) === 0)
|
971 |
+
{
|
972 |
+
$key = substr($key, strlen(SF_FPRE));
|
973 |
+
}
|
974 |
+
|
975 |
+
$the_post_tax = $val;
|
976 |
+
|
977 |
+
//make the post an array for easy looping
|
978 |
+
if(!is_array($val))
|
979 |
+
{
|
980 |
+
$post_tax[] = $the_post_tax;
|
981 |
+
}
|
982 |
+
else
|
983 |
+
{
|
984 |
+
$post_tax = $the_post_tax;
|
985 |
+
}
|
986 |
+
$taxarr = array();
|
987 |
+
|
988 |
+
foreach ($post_tax as $tax)
|
989 |
+
{
|
990 |
+
$tax = esc_attr($tax);
|
991 |
+
$taxobj = get_term_by('id',$tax,$key);
|
992 |
+
|
993 |
+
if(isset($taxobj->slug))
|
994 |
+
{
|
995 |
+
$taxarr[] = $taxobj->slug;
|
996 |
+
}
|
997 |
+
}
|
998 |
+
|
999 |
+
|
1000 |
+
if(count($taxarr)>0)
|
1001 |
+
{
|
1002 |
+
$operator = "+"; //default behaviour
|
1003 |
+
|
1004 |
+
//check to see if an operator has been specified - only applies with fields that use multiple selects such as checkboxes or multi selects
|
1005 |
+
if(isset($_POST[SF_FPRE.$key.'_operator']))
|
1006 |
+
{
|
1007 |
+
if($_POST[SF_FPRE.$key.'_operator']=="and")
|
1008 |
+
{
|
1009 |
+
$operator = "+";
|
1010 |
+
}
|
1011 |
+
else if($_POST[SF_FPRE.$key.'_operator']=="or")
|
1012 |
+
{
|
1013 |
+
$operator = ",";
|
1014 |
+
}
|
1015 |
+
else
|
1016 |
+
{
|
1017 |
+
$operator = "+";
|
1018 |
+
}
|
1019 |
+
}
|
1020 |
+
|
1021 |
+
$tags = implode($operator,$taxarr);
|
1022 |
+
|
1023 |
+
if(!$this->hasqmark)
|
1024 |
+
{
|
1025 |
+
$this->urlparams .= "?";
|
1026 |
+
$this->hasqmark = true;
|
1027 |
+
}
|
1028 |
+
else
|
1029 |
+
{
|
1030 |
+
$this->urlparams .= "&";
|
1031 |
+
}
|
1032 |
+
$this->urlparams .= $key."=".$tags;
|
1033 |
+
|
1034 |
+
}
|
1035 |
+
}
|
1036 |
+
}
|
1037 |
+
}
|
1038 |
+
|
1039 |
+
|
1040 |
+
if($this->has_form_posted)
|
1041 |
+
{//if the search has been posted, redirect to the newly formed url with all the right params
|
1042 |
+
|
1043 |
+
if($this->urlparams=="/")
|
1044 |
+
{//check to see if url params are set, if not ("/") then add "?s=" to force load search results, without this it would redirect to the homepage, which may be a custom page with no blog items/results
|
1045 |
+
$this->urlparams .= "?s=";
|
1046 |
+
}
|
1047 |
+
|
1048 |
+
if($this->urlparams=="/?s=")
|
1049 |
+
{//if a blank search was submitted - need to check for this string here in case `add_search_param` has already added a "?s=" to the url
|
1050 |
+
|
1051 |
+
if(isset($_POST[SF_FPRE.'empty_search_url']))
|
1052 |
+
{//then redirect to the provided empty search url
|
1053 |
+
|
1054 |
+
wp_redirect(esc_url($_POST[SF_FPRE.'empty_search_url']));
|
1055 |
+
exit;
|
1056 |
+
}
|
1057 |
+
}
|
1058 |
+
|
1059 |
+
wp_redirect((home_url().$this->urlparams));
|
1060 |
+
}
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
public function get_search_filter_form($submitlabel, $search_placeholder, $fields, $types, $labels, $hierarchical, $hide_empty, $show_count, $post_types, $order_by, $order_dir, $operators, $all_items_labels, $empty_search_url, $add_search_param, $class)
|
1064 |
+
{
|
1065 |
+
$returnvar = '';
|
1066 |
+
|
1067 |
+
$addclass = "";
|
1068 |
+
if($class!="")
|
1069 |
+
{
|
1070 |
+
$addclass = ' '.$class;
|
1071 |
+
}
|
1072 |
+
|
1073 |
+
$returnvar .= '
|
1074 |
+
<form action="" method="post" class="searchandfilter'.$addclass.'">
|
1075 |
+
<div>';
|
1076 |
+
|
1077 |
+
if(!in_array("post_types", $fields))
|
1078 |
+
{//then the user has not added it to the fields list so the user does not want a post types drop down... so add (if any) the post types to a hidden attribute
|
1079 |
+
|
1080 |
+
if(($post_types!="")&&(is_array($post_types)))
|
1081 |
+
{
|
1082 |
+
foreach($post_types as $post_type)
|
1083 |
+
{
|
1084 |
+
$returnvar .= "<input type=\"hidden\" name=\"".SF_FPRE."post_types[]\" value=\"".$post_type."\" />";
|
1085 |
+
}
|
1086 |
+
}
|
1087 |
+
}
|
1088 |
+
$returnvar .= '
|
1089 |
+
<ul>';
|
1090 |
+
|
1091 |
+
$i = 0;
|
1092 |
+
|
1093 |
+
foreach($fields as $field)
|
1094 |
+
{
|
1095 |
+
//special cases - post_types & post_date.. all others assumed regular wp taxonomy
|
1096 |
+
|
1097 |
+
if($field == "search")
|
1098 |
+
{
|
1099 |
+
$returnvar .= '<li>';
|
1100 |
+
if($labels[$i]!="")
|
1101 |
+
{
|
1102 |
+
$returnvar .= "<h4>".$labels[$i]."</h4>";
|
1103 |
+
}
|
1104 |
+
$clean_searchterm = (esc_attr($this->searchterm));
|
1105 |
+
$returnvar .= '<input type="text" name="'.SF_FPRE.'search" placeholder="'.$search_placeholder.'" value="'.$clean_searchterm.'">';
|
1106 |
+
$returnvar .= '</li>';
|
1107 |
+
}
|
1108 |
+
else if($field == "post_types") //a post can only every have 1 type, so checkboxes & multiselects will always be "OR"
|
1109 |
+
{//build field array
|
1110 |
+
|
1111 |
+
//check to see if operator is set for this field
|
1112 |
+
/*if(isset($operators[$i]))
|
1113 |
+
{
|
1114 |
+
$operators[$i] = strtolower($operators[$i]);
|
1115 |
+
|
1116 |
+
if(($operators[$i]=="and")||($operators[$i]=="or"))
|
1117 |
+
{
|
1118 |
+
$returnvar .= '<input type="hidden" name="'.SF_FPRE.$field.'_operator" value="'.$operators[$i].'" />';
|
1119 |
+
}
|
1120 |
+
}*/
|
1121 |
+
|
1122 |
+
|
1123 |
+
$returnvar .= $this->build_post_type_element($types, $labels, $post_types, $field, $all_items_labels, $i);
|
1124 |
+
|
1125 |
+
}
|
1126 |
+
else if($field == 'post_date')
|
1127 |
+
{
|
1128 |
+
$returnvar .= $this->build_post_date_element($labels, $i, $types, $field);
|
1129 |
+
}
|
1130 |
+
else
|
1131 |
+
{
|
1132 |
+
$returnvar .= $this->build_taxonomy_element($types, $labels, $field, $hierarchical, $hide_empty, $show_count, $order_by, $order_dir, $operators, $all_items_labels, $i);
|
1133 |
+
}
|
1134 |
+
$i++;
|
1135 |
+
|
1136 |
+
}
|
1137 |
+
|
1138 |
+
$returnvar .='<li>';
|
1139 |
+
|
1140 |
+
if($add_search_param==1)
|
1141 |
+
{
|
1142 |
+
$returnvar .= "<input type=\"hidden\" name=\"".SF_FPRE."add_search_param\" value=\"1\" />";
|
1143 |
+
}
|
1144 |
+
|
1145 |
+
if($empty_search_url!="")
|
1146 |
+
{
|
1147 |
+
$returnvar .= "<input type=\"hidden\" name=\"".SF_FPRE."empty_search_url\" value=\"".esc_url($empty_search_url)."\" />";
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
|
1151 |
+
$returnvar .=
|
1152 |
+
'<input type="hidden" name="'.SF_FPRE.'submitted" value="1">
|
1153 |
+
<input type="submit" value="'.$submitlabel.'">
|
1154 |
+
</li>';
|
1155 |
+
|
1156 |
+
$returnvar .= "</ul>";
|
1157 |
+
$returnvar .= '</div>
|
1158 |
+
</form>';
|
1159 |
+
|
1160 |
+
return $returnvar;
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
///////////////////////////////////////////////////////////
|
1164 |
+
function build_post_date_element($labels, $i, $types, $field)
|
1165 |
+
{
|
1166 |
+
$returnvar = "";
|
1167 |
+
|
1168 |
+
$taxonomychildren = array();
|
1169 |
+
|
1170 |
+
$taxonomychildren = (object)$taxonomychildren;
|
1171 |
+
|
1172 |
+
$returnvar .= "<li>";
|
1173 |
+
|
1174 |
+
if($labels[$i]!="")
|
1175 |
+
{
|
1176 |
+
$returnvar .= "<h4>".$labels[$i]."</h4>";
|
1177 |
+
}
|
1178 |
+
|
1179 |
+
$defaultval = "";
|
1180 |
+
|
1181 |
+
if($types[$i]=="date")
|
1182 |
+
{
|
1183 |
+
$returnvar .= $this->generate_date($taxonomychildren, $field, $this->tagid);
|
1184 |
+
}
|
1185 |
+
if($types[$i]=="daterange")
|
1186 |
+
{
|
1187 |
+
$returnvar .= $this->generate_date($taxonomychildren, $field, 0);
|
1188 |
+
$returnvar .= "</li><li>";
|
1189 |
+
$returnvar .= $this->generate_date($taxonomychildren, $field, 1);
|
1190 |
+
}
|
1191 |
+
$returnvar .= "</li>";
|
1192 |
+
|
1193 |
+
return $returnvar;
|
1194 |
+
}
|
1195 |
+
|
1196 |
+
|
1197 |
+
function build_post_type_element($types, $labels, $post_types, $field, $all_items_labels, $i)
|
1198 |
+
{
|
1199 |
+
$returnvar = "";
|
1200 |
+
$taxonomychildren = array();
|
1201 |
+
$post_type_count = count($post_types);
|
1202 |
+
|
1203 |
+
//then check the post types array
|
1204 |
+
if(is_array($post_types))
|
1205 |
+
{
|
1206 |
+
if(($post_type_count==1)&&($post_types[0]=="all"))
|
1207 |
+
{
|
1208 |
+
$args = array('public' => true);
|
1209 |
+
$output = 'object'; // names or objects, note names is the default
|
1210 |
+
$operator = 'and'; // 'and' or 'or'
|
1211 |
+
|
1212 |
+
$post_types_objs = get_post_types( $args, $output, $operator );
|
1213 |
+
|
1214 |
+
$post_types = array();
|
1215 |
+
|
1216 |
+
foreach ( $post_types_objs as $post_type )
|
1217 |
+
{
|
1218 |
+
if($post_type->name!="attachment")
|
1219 |
+
{
|
1220 |
+
$tempobject = array();
|
1221 |
+
$tempobject['term_id'] = $post_type->name;
|
1222 |
+
$tempobject['cat_name'] = $post_type->labels->name;
|
1223 |
+
|
1224 |
+
$taxonomychildren[] = (object)$tempobject;
|
1225 |
+
|
1226 |
+
$post_types[] = $post_type->name;
|
1227 |
+
|
1228 |
+
}
|
1229 |
+
}
|
1230 |
+
$post_type_count = count($post_types_objs);
|
1231 |
+
|
1232 |
+
}
|
1233 |
+
else
|
1234 |
+
{
|
1235 |
+
foreach($post_types as $post_type)
|
1236 |
+
{
|
1237 |
+
//var_dump(get_post_type_object( $post_type ));
|
1238 |
+
$post_type_data = get_post_type_object( $post_type );
|
1239 |
+
|
1240 |
+
if($post_type_data)
|
1241 |
+
{
|
1242 |
+
$tempobject = array();
|
1243 |
+
$tempobject['term_id'] = $post_type;
|
1244 |
+
$tempobject['cat_name'] = $post_type_data->labels->name;
|
1245 |
+
|
1246 |
+
$taxonomychildren[] = (object)$tempobject;
|
1247 |
+
}
|
1248 |
+
}
|
1249 |
+
}
|
1250 |
+
}
|
1251 |
+
$taxonomychildren = (object)$taxonomychildren;
|
1252 |
+
|
1253 |
+
$returnvar .= "<li>";
|
1254 |
+
|
1255 |
+
$post_type_labels = array();
|
1256 |
+
$post_type_labels['name'] = "Post Types";
|
1257 |
+
$post_type_labels['singular_name'] = "Post Type";
|
1258 |
+
$post_type_labels['search_items'] = "Search Post Types";
|
1259 |
+
|
1260 |
+
if($all_items_labels[$i]!="")
|
1261 |
+
{
|
1262 |
+
$post_type_labels['all_items'] = $all_items_labels[$i];
|
1263 |
+
}
|
1264 |
+
else
|
1265 |
+
{
|
1266 |
+
$post_type_labels['all_items'] = "All Post Types";
|
1267 |
+
}
|
1268 |
+
|
1269 |
+
$post_type_labels = (object)$post_type_labels;
|
1270 |
+
|
1271 |
+
if($labels[$i]!="")
|
1272 |
+
{
|
1273 |
+
$returnvar .= "<h4>".$labels[$i]."</h4>";
|
1274 |
+
}
|
1275 |
+
|
1276 |
+
if($post_type_count>0)
|
1277 |
+
{
|
1278 |
+
$defaultval = implode(",",$post_types);
|
1279 |
+
}
|
1280 |
+
else
|
1281 |
+
{
|
1282 |
+
$defaultval = "all";
|
1283 |
+
}
|
1284 |
+
|
1285 |
+
if($types[$i]=="select")
|
1286 |
+
{
|
1287 |
+
$returnvar .= $this->generate_select($taxonomychildren, $field, $this->tagid, $post_type_labels, $defaultval);
|
1288 |
+
}
|
1289 |
+
else if($types[$i]=="checkbox")
|
1290 |
+
{
|
1291 |
+
|
1292 |
+
$returnvar .= $this->generate_checkbox($taxonomychildren, $field, $this->tagid);
|
1293 |
+
}
|
1294 |
+
else if($types[$i]=="radio")
|
1295 |
+
{
|
1296 |
+
$returnvar .= $this->generate_radio($taxonomychildren, $field, $this->tagid, $post_type_labels, $defaultval);
|
1297 |
+
}
|
1298 |
+
$returnvar .= "</li>";
|
1299 |
+
|
1300 |
+
return $returnvar;
|
1301 |
+
}
|
1302 |
+
|
1303 |
+
//gets all the data for the taxonomy then display as form element
|
1304 |
+
function build_taxonomy_element($types, $labels, $taxonomy, $hierarchical, $hide_empty, $show_count, $order_by, $order_dir, $operators, $all_items_labels, $i)
|
1305 |
+
{
|
1306 |
+
$returnvar = "";
|
1307 |
+
|
1308 |
+
$taxonomydata = get_taxonomy($taxonomy);
|
1309 |
+
|
1310 |
+
if($taxonomydata)
|
1311 |
+
{
|
1312 |
+
$returnvar .= "<li>";
|
1313 |
+
|
1314 |
+
if($labels[$i]!="")
|
1315 |
+
{
|
1316 |
+
$returnvar .= "<h4>".$labels[$i]."</h4>";
|
1317 |
+
}
|
1318 |
+
|
1319 |
+
$args = array(
|
1320 |
+
'name' => SF_FPRE . $taxonomy,
|
1321 |
+
'taxonomy' => $taxonomy,
|
1322 |
+
'hierarchical' => false,
|
1323 |
+
'child_of' => 0,
|
1324 |
+
'echo' => false,
|
1325 |
+
'hide_if_empty' => false,
|
1326 |
+
'hide_empty' => true,
|
1327 |
+
'order' => $order_dir[$i],
|
1328 |
+
'orderby' => $order_by[$i],
|
1329 |
+
'show_option_none' => '',
|
1330 |
+
'show_count' => '0',
|
1331 |
+
'show_option_all' => '',
|
1332 |
+
'show_option_all_sf' => ''
|
1333 |
+
);
|
1334 |
+
|
1335 |
+
if(isset($hierarchical[$i]))
|
1336 |
+
{
|
1337 |
+
if($hierarchical[$i]==1)
|
1338 |
+
{
|
1339 |
+
$args['hierarchical'] = true;
|
1340 |
+
}
|
1341 |
+
}
|
1342 |
+
|
1343 |
+
if(isset($hide_empty[$i]))
|
1344 |
+
{
|
1345 |
+
if($hide_empty[$i]==0)
|
1346 |
+
{
|
1347 |
+
$args['hide_empty'] = false;
|
1348 |
+
}
|
1349 |
+
}
|
1350 |
+
|
1351 |
+
if(isset($show_count[$i]))
|
1352 |
+
{
|
1353 |
+
if($show_count[$i]==1)
|
1354 |
+
{
|
1355 |
+
$args['show_count'] = true;
|
1356 |
+
}
|
1357 |
+
}
|
1358 |
+
|
1359 |
+
if($all_items_labels[$i]!="")
|
1360 |
+
{
|
1361 |
+
$args['show_option_all_sf'] = $all_items_labels[$i];
|
1362 |
+
}
|
1363 |
+
|
1364 |
+
|
1365 |
+
|
1366 |
+
$taxonomychildren = get_categories($args);
|
1367 |
+
|
1368 |
+
if($types[$i]=="select")
|
1369 |
+
{
|
1370 |
+
$returnvar .= $this->generate_wp_dropdown($args, $taxonomy, $this->tagid, $taxonomydata->labels);
|
1371 |
+
}
|
1372 |
+
else if($types[$i]=="checkbox")
|
1373 |
+
{
|
1374 |
+
$args['title_li'] = '';
|
1375 |
+
$args['defaults'] = "";
|
1376 |
+
if(isset($this->defaults[$args['name']]))
|
1377 |
+
{
|
1378 |
+
$args['defaults'] = $this->defaults[$args['name']];
|
1379 |
+
}
|
1380 |
+
//$args['show_option_all'] = 0;
|
1381 |
+
|
1382 |
+
$returnvar .= $this->generate_wp_checkbox($args, $taxonomy, $this->tagid, $taxonomydata->labels);
|
1383 |
+
}
|
1384 |
+
else if($types[$i]=="radio")
|
1385 |
+
{
|
1386 |
+
$args['title_li'] = '';
|
1387 |
+
$args['defaults'] = "";
|
1388 |
+
if(isset($this->defaults[$args['name']]))
|
1389 |
+
{
|
1390 |
+
$args['defaults'] = $this->defaults[$args['name']];
|
1391 |
+
}
|
1392 |
+
|
1393 |
+
$returnvar .= $this->generate_wp_radio($args, $taxonomy, $this->tagid, $taxonomydata->labels);
|
1394 |
+
}
|
1395 |
+
else if($types[$i]=="multiselect")
|
1396 |
+
{
|
1397 |
+
$args['title_li'] = '';
|
1398 |
+
$args['defaults'] = "";
|
1399 |
+
if(isset($this->defaults[$args['name']]))
|
1400 |
+
{
|
1401 |
+
$args['defaults'] = $this->defaults[$args['name']];
|
1402 |
+
}
|
1403 |
+
|
1404 |
+
$returnvar .= $this->generate_wp_multiselect($args, $taxonomy, $this->tagid, $taxonomydata->labels);
|
1405 |
+
}
|
1406 |
+
|
1407 |
+
//check to see if operator is set for this field
|
1408 |
+
if(isset($operators[$i]))
|
1409 |
+
{
|
1410 |
+
$operators[$i] = strtolower($operators[$i]);
|
1411 |
+
|
1412 |
+
if(($operators[$i]=="and")||($operators[$i]=="or"))
|
1413 |
+
{
|
1414 |
+
$returnvar .= '<input type="hidden" name="'.SF_FPRE.$taxonomy.'_operator" value="'.$operators[$i].'" />';
|
1415 |
+
}
|
1416 |
+
}
|
1417 |
+
|
1418 |
+
$returnvar .= "</li>";
|
1419 |
+
}
|
1420 |
+
|
1421 |
+
return $returnvar;
|
1422 |
+
}
|
1423 |
+
|
1424 |
+
|
1425 |
+
/*
|
1426 |
+
* Display various forms
|
1427 |
+
*/
|
1428 |
+
|
1429 |
+
//use wp array walker to enable hierarchical display
|
1430 |
+
public function generate_wp_dropdown($args, $name, $currentid = 0, $labels = null, $defaultval = "0")
|
1431 |
+
{
|
1432 |
+
$returnvar = '';
|
1433 |
+
|
1434 |
+
if($args['show_option_all_sf']=="")
|
1435 |
+
{
|
1436 |
+
$args['show_option_all'] = $labels->all_items != "" ? $labels->all_items : 'All ' . $labels->name;
|
1437 |
+
}
|
1438 |
+
else
|
1439 |
+
{
|
1440 |
+
$args['show_option_all'] = $args['show_option_all_sf'];
|
1441 |
+
}
|
1442 |
+
|
1443 |
+
if(isset($this->defaults[SF_FPRE.$name]))
|
1444 |
+
{
|
1445 |
+
$defaults = $this->defaults[SF_FPRE . $name];
|
1446 |
+
if (is_array($defaults)) {
|
1447 |
+
if (count($defaults) == 1) {
|
1448 |
+
$args['selected'] = $defaults[0];
|
1449 |
+
}
|
1450 |
+
}
|
1451 |
+
else {
|
1452 |
+
$args['selected'] = $defaultval;
|
1453 |
+
}
|
1454 |
+
}
|
1455 |
+
|
1456 |
+
$returnvar .= wp_dropdown_categories($args);
|
1457 |
+
|
1458 |
+
return $returnvar;
|
1459 |
+
}
|
1460 |
+
|
1461 |
+
//use wp array walker to enable hierarchical display
|
1462 |
+
public function generate_wp_multiselect($args, $name, $currentid = 0, $labels = null, $defaultval = "0")
|
1463 |
+
{
|
1464 |
+
$returnvar = '<select multiple="multiple" name="'.$args['name'].'[]" class="postform">';
|
1465 |
+
$returnvar .= walk_taxonomy('multiselect', $args);
|
1466 |
+
$returnvar .= "</select>";
|
1467 |
+
|
1468 |
+
return $returnvar;
|
1469 |
+
}
|
1470 |
+
|
1471 |
+
//use wp array walker to enable hierarchical display
|
1472 |
+
public function generate_wp_checkbox($args, $name, $currentid = 0, $labels = null, $defaultval = "0")
|
1473 |
+
{
|
1474 |
+
$returnvar = '<ul>';
|
1475 |
+
$returnvar .= walk_taxonomy('checkbox', $args);
|
1476 |
+
$returnvar .= "</ul>";
|
1477 |
+
|
1478 |
+
return $returnvar;
|
1479 |
+
}
|
1480 |
+
|
1481 |
+
//use wp array walker to enable hierarchical display
|
1482 |
+
public function generate_wp_radio($args, $name, $currentid = 0, $labels = null, $defaultval = "0")
|
1483 |
+
{
|
1484 |
+
|
1485 |
+
if($args['show_option_all_sf']=="")
|
1486 |
+
{
|
1487 |
+
$show_option_all = $labels->all_items != "" ? $labels->all_items : 'All ' . $labels->name;
|
1488 |
+
}
|
1489 |
+
else
|
1490 |
+
{
|
1491 |
+
$show_option_all = $args['show_option_all_sf'];
|
1492 |
+
}
|
1493 |
+
|
1494 |
+
$checked = ($defaultval=="0") ? " checked='checked'" : "";
|
1495 |
+
$returnvar = '<ul>';
|
1496 |
+
$returnvar .= '<li>'."<label><input type='radio' name='".$args['name']."[]' value='0'$checked /> ".$show_option_all."</label>".'</li>';
|
1497 |
+
$returnvar .= walk_taxonomy('radio', $args);
|
1498 |
+
$returnvar .= "</ul>";
|
1499 |
+
|
1500 |
+
return $returnvar;
|
1501 |
+
}
|
1502 |
+
|
1503 |
+
//generate generic form inputs for use elsewhere, such as post types and non taxonomy fields
|
1504 |
+
public function generate_select($dropdata, $name, $currentid = 0, $labels = null, $defaultval = "0")
|
1505 |
+
{
|
1506 |
+
$returnvar = "";
|
1507 |
+
|
1508 |
+
$returnvar .= '<select class="postform" name="'.SF_FPRE.$name.'">';
|
1509 |
+
if(isset($labels))
|
1510 |
+
{
|
1511 |
+
if($labels->all_items!="")
|
1512 |
+
{//check to see if all items has been registered in field then use this label
|
1513 |
+
$returnvar .= '<option class="level-0" value="'.$defaultval.'">'.$labels->all_items.'</option>';
|
1514 |
+
}
|
1515 |
+
else
|
1516 |
+
{//check to see if all items has been registered in field then use this label with prefix of "All"
|
1517 |
+
$returnvar .= '<option class="level-0" value="'.$defaultval.'">All '.$labels->name.'</option>';
|
1518 |
+
}
|
1519 |
+
}
|
1520 |
+
|
1521 |
+
foreach($dropdata as $dropdown)
|
1522 |
+
{
|
1523 |
+
$selected = "";
|
1524 |
+
|
1525 |
+
if(isset($this->defaults[SF_FPRE.$name]))
|
1526 |
+
{
|
1527 |
+
$defaults = $this->defaults[SF_FPRE.$name];
|
1528 |
+
|
1529 |
+
$noselected = count($defaults);
|
1530 |
+
|
1531 |
+
if(($noselected==1)&&(is_array($defaults))) //there should never be more than 1 default in a select, if there are then don't set any, user is obviously searching multiple values, in the case of a select this must be "all"
|
1532 |
+
{
|
1533 |
+
foreach($defaults as $defaultid)
|
1534 |
+
{
|
1535 |
+
if($defaultid==$dropdown->term_id)
|
1536 |
+
{
|
1537 |
+
$selected = ' selected="selected"';
|
1538 |
+
}
|
1539 |
+
}
|
1540 |
+
}
|
1541 |
+
}
|
1542 |
+
$returnvar .= '<option class="level-0" value="'.$dropdown->term_id.'"'.$selected.'>'.$dropdown->cat_name.'</option>';
|
1543 |
+
|
1544 |
+
}
|
1545 |
+
$returnvar .= "</select>";
|
1546 |
+
|
1547 |
+
return $returnvar;
|
1548 |
+
}
|
1549 |
+
|
1550 |
+
public function generate_checkbox($dropdata, $name, $currentid = 0, $labels = null, $defaultval = '')
|
1551 |
+
{
|
1552 |
+
$returnvar = '<ul>';
|
1553 |
+
|
1554 |
+
foreach($dropdata as $dropdown)
|
1555 |
+
{
|
1556 |
+
$checked = "";
|
1557 |
+
|
1558 |
+
//check a default has been set
|
1559 |
+
if(isset($this->defaults[SF_FPRE.$name]))
|
1560 |
+
{
|
1561 |
+
$defaults = $this->defaults[SF_FPRE.$name];
|
1562 |
+
|
1563 |
+
$noselected = count($defaults);
|
1564 |
+
|
1565 |
+
if(($noselected>0)&&(is_array($defaults)))
|
1566 |
+
{
|
1567 |
+
foreach($defaults as $defaultid)
|
1568 |
+
{
|
1569 |
+
if($defaultid==$dropdown->term_id)
|
1570 |
+
{
|
1571 |
+
$checked = ' checked="checked"';
|
1572 |
+
}
|
1573 |
+
}
|
1574 |
+
}
|
1575 |
+
}
|
1576 |
+
$returnvar .= '<li class="cat-item"><label><input class="postform cat-item" type="checkbox" name="'.SF_FPRE.$name.'[]" value="'.$dropdown->term_id.'"'.$checked.'> '.$dropdown->cat_name.'</label></li>';
|
1577 |
+
|
1578 |
+
}
|
1579 |
+
|
1580 |
+
$returnvar .= '</ul>';
|
1581 |
+
|
1582 |
+
return $returnvar;
|
1583 |
+
}
|
1584 |
+
|
1585 |
+
|
1586 |
+
public function generate_radio($dropdata, $name, $currentid = 0, $labels = null, $defaultval = "0")
|
1587 |
+
{
|
1588 |
+
$returnvar = '<ul>';
|
1589 |
+
|
1590 |
+
if(isset($labels))
|
1591 |
+
{
|
1592 |
+
$checked = "";
|
1593 |
+
if(isset($this->defaults[SF_FPRE.$name]))
|
1594 |
+
{
|
1595 |
+
$defaults = $this->defaults[SF_FPRE.$name];
|
1596 |
+
$noselected = count($defaults);
|
1597 |
+
|
1598 |
+
if($noselected==0)
|
1599 |
+
{
|
1600 |
+
$checked = ' checked="checked"';
|
1601 |
+
}
|
1602 |
+
else if($noselected==1)
|
1603 |
+
{
|
1604 |
+
if($this->defaults[SF_FPRE.$name][0]==$defaultval)
|
1605 |
+
{
|
1606 |
+
$checked = ' checked="checked"';
|
1607 |
+
}
|
1608 |
+
}
|
1609 |
+
}
|
1610 |
+
else
|
1611 |
+
{
|
1612 |
+
$checked = ' checked="checked"';
|
1613 |
+
}
|
1614 |
+
|
1615 |
+
if(isset($this->defaults[SF_FPRE.$name]))
|
1616 |
+
{
|
1617 |
+
$defaults = $this->defaults[SF_FPRE.$name];
|
1618 |
+
if(count($defaults)>1)
|
1619 |
+
{//then we are dealing with multiple defaults - this means mutliple radios are selected, this is only possible with "ALL" so set as default.
|
1620 |
+
$checked = ' checked="checked"';
|
1621 |
+
}
|
1622 |
+
}
|
1623 |
+
|
1624 |
+
$all_items_name = "";
|
1625 |
+
if($labels->all_items!="")
|
1626 |
+
{//check to see if all items has been registered in field then use this label
|
1627 |
+
$all_items_name = $labels->all_items;
|
1628 |
+
}
|
1629 |
+
else
|
1630 |
+
{//check to see if all items has been registered in field then use this label with prefix of "All"
|
1631 |
+
$all_items_name = "All ".$labels->name;
|
1632 |
+
}
|
1633 |
+
|
1634 |
+
$returnvar .= '<li class="cat-item"><label><input class="postform" type="radio" name="'.SF_FPRE.$name.'[]" value="'.$defaultval.'"'.$checked.'> '.$all_items_name.'</label></li>';
|
1635 |
+
}
|
1636 |
+
|
1637 |
+
foreach($dropdata as $dropdown)
|
1638 |
+
{
|
1639 |
+
$checked = "";
|
1640 |
+
|
1641 |
+
//check a default has been set
|
1642 |
+
if(isset($this->defaults[SF_FPRE.$name]))
|
1643 |
+
{
|
1644 |
+
$defaults = $this->defaults[SF_FPRE.$name];
|
1645 |
+
|
1646 |
+
$noselected = count($defaults);
|
1647 |
+
|
1648 |
+
if(($noselected==1)&&(is_array($defaults)))
|
1649 |
+
{
|
1650 |
+
foreach($defaults as $defaultid)
|
1651 |
+
{
|
1652 |
+
if($defaultid==$dropdown->term_id)
|
1653 |
+
{
|
1654 |
+
$checked = ' checked="checked"';
|
1655 |
+
}
|
1656 |
+
}
|
1657 |
+
}
|
1658 |
+
}
|
1659 |
+
$returnvar .= '<li class="cat-item"><label><input class="postform" type="radio" name="'.SF_FPRE.$name.'[]" value="'.$dropdown->term_id.'"'.$checked.'> '.$dropdown->cat_name.'</label></li>';
|
1660 |
+
|
1661 |
+
}
|
1662 |
+
|
1663 |
+
$returnvar .= '</ul>';
|
1664 |
+
|
1665 |
+
return $returnvar;
|
1666 |
+
}
|
1667 |
+
|
1668 |
+
public function generate_date($dropdata, $name, $currentid = 0, $labels = null, $defaultval = "0")
|
1669 |
+
{
|
1670 |
+
$returnvar = '';
|
1671 |
+
$current_date = '';
|
1672 |
+
//check a default has been set - upto two possible vars for array
|
1673 |
+
|
1674 |
+
if(isset($this->defaults[SF_FPRE.$name]))
|
1675 |
+
{
|
1676 |
+
$defaults = $this->defaults[SF_FPRE.$name];
|
1677 |
+
|
1678 |
+
$noselected = count($defaults);
|
1679 |
+
|
1680 |
+
if(($noselected>0)&&(is_array($defaults)))
|
1681 |
+
{
|
1682 |
+
$current_date = $defaults[$currentid];
|
1683 |
+
}
|
1684 |
+
}
|
1685 |
+
|
1686 |
+
$returnvar .= '<input class="postform" type="date" name="'.SF_FPRE.$name.'[]" value="' . $current_date . '" />';
|
1687 |
+
|
1688 |
+
return $returnvar;
|
1689 |
+
}
|
1690 |
+
}
|
1691 |
+
}
|
1692 |
+
|
1693 |
+
|
1694 |
+
function walk_taxonomy( $type = "checkbox", $args = array() ) {
|
1695 |
+
|
1696 |
+
$args['walker'] = new Taxonomy_Walker($type, $args['name']);
|
1697 |
+
|
1698 |
+
$output = wp_list_categories($args);
|
1699 |
+
if ( $output )
|
1700 |
+
return $output;
|
1701 |
+
}
|
1702 |
+
|
1703 |
+
|
1704 |
+
|
1705 |
+
|
1706 |
+
if ( class_exists( 'SearchAndFilter' ) )
|
1707 |
+
{
|
1708 |
+
global $SearchAndFilter;
|
1709 |
+
$SearchAndFilter = new SearchAndFilter();
|
1710 |
+
}
|
1711 |
+
|
1712 |
+
/*
|
1713 |
+
* Includes
|
1714 |
+
*/
|
1715 |
+
|
1716 |
+
// classes
|
1717 |
+
require_once(SEARCHANDFILTER_PLUGIN_DIR."/of-list-table.php");
|
1718 |
+
require_once(SEARCHANDFILTER_PLUGIN_DIR."/of-taxonomy-walker.php");
|
1719 |
+
|
1720 |
+
// admin screens & plugin mods
|
1721 |
+
require_once(SEARCHANDFILTER_PLUGIN_DIR."/of-admin.php");
|
1722 |
+
|
1723 |
+
|
1724 |
?>
|