Search & Filter - Version 1.2.7

Version Description

  • Fixed - fix for new taxonomy rewrites and problems with multiple selection when using checkboxes
  • Fixed - added previously hidden multiselect field type
Download this release

Release Info

Developer DesignsAndCode
Plugin Icon 128x128 Search & Filter
Version 1.2.7
Comparing to
See all releases

Code changes from version 1.2.6 to 1.2.7

Files changed (5) hide show
  1. of-admin.php +1 -1
  2. of-list-table.php +1 -1
  3. of-taxonomy-walker.php +3 -3
  4. readme.txt +5 -1
  5. search-filter.php +161 -148
of-admin.php CHANGED
@@ -47,7 +47,7 @@
47
  echo '<div class="of-caption">
48
  Search &amp; Filter is a simple search and filtering plugin for Wordpress brought to you by <a href="http://www.designsandcode.com" target="_blank">Designs &amp; Code</a>.<br /><br />
49
  It is essentially an advancement of the WordPress search box, adding taxonomy and post type filters to really refine your searches.<br /><br />
50
- You can search by Category, Tag, Custom Taxonomy, Post Type or any combination of these easily - you can even remove the search box and simply use it as a filtering system for your posts and pages. Taxonomies and Post Types can be displayed as dropdown selects, checkboxes or radio buttons.
51
  </div>';
52
  echo "<h3>Documentation</h3>";
53
  echo '<div class="of-caption">
47
  echo '<div class="of-caption">
48
  Search &amp; Filter is a simple search and filtering plugin for Wordpress brought to you by <a href="http://www.designsandcode.com" target="_blank">Designs &amp; Code</a>.<br /><br />
49
  It is essentially an advancement of the WordPress search box, adding taxonomy and post type filters to really refine your searches.<br /><br />
50
+ You can search by Category, Tag, Custom Taxonomy, Post Type or any combination of these easily - you can even remove the search box and simply use it as a filtering system for your posts and pages. Taxonomies and Post Types can be displayed as dropdown selects, checkboxes, radio buttons or multiselects.
51
  </div>';
52
  echo "<h3>Documentation</h3>";
53
  echo '<div class="of-caption">
of-list-table.php CHANGED
@@ -199,7 +199,7 @@ class OF_Variable_List_Table extends WP_List_Table {
199
  "ID" => $counter,
200
  "name" => "types",
201
  "defaultval" => "<code class='string large'>select</code>",
202
- "options" => "<em>Comma seperated list of any of the types found below:</em><br /><br />select<br />checkbox<br />radio<br /><br />
203
  <em>These types should only be used when the field is `post_date`:</em><br /><br />date<br />daterange",
204
  "info" => "The order of values in this comma seperated list needs to match the fields list."
205
  );
199
  "ID" => $counter,
200
  "name" => "types",
201
  "defaultval" => "<code class='string large'>select</code>",
202
+ "options" => "<em>Comma seperated list of any of the types found below:</em><br /><br />select<br />checkbox<br />radio<br />multiselect<br /><br />
203
  <em>These types should only be used when the field is `post_date`:</em><br /><br />date<br />daterange",
204
  "info" => "The order of values in this comma seperated list needs to match the fields list."
205
  );
of-taxonomy-walker.php CHANGED
@@ -47,7 +47,7 @@ class Taxonomy_Walker extends Walker_Category {
47
  {
48
  extract($args);
49
 
50
- $cat_name = esc_attr( $category->sf_name );
51
  $cat_name = apply_filters( 'list_cats', $cat_name, $category );
52
  $link = '<a href="' . esc_url( get_term_link($category) ) . '" ';
53
  if ( $use_desc_for_title == 0 || empty($category->description) )
@@ -161,8 +161,8 @@ class Taxonomy_Walker extends Walker_Category {
161
  else if($this->type=="multiselect")
162
  {
163
  extract($args);
164
-
165
- $cat_name = esc_attr( $category->sf_name );
166
  $cat_id = esc_attr( $category->term_id );
167
  $cat_name = apply_filters( 'list_cats', $cat_name, $category );
168
 
47
  {
48
  extract($args);
49
 
50
+ $cat_name = esc_attr( $sf_name );
51
  $cat_name = apply_filters( 'list_cats', $cat_name, $category );
52
  $link = '<a href="' . esc_url( get_term_link($category) ) . '" ';
53
  if ( $use_desc_for_title == 0 || empty($category->description) )
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
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: category, filter, taxonomy, search, wordpress, post type, post date
5
  Requires at least: 3.5
6
  Tested up to: 4.2.1
7
- Stable tag: 1.2.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -34,6 +34,10 @@ The documentation has been updated to include examples almost all configurable o
34
 
35
  == Changelog ==
36
 
 
 
 
 
37
  = 1.2.6 =
38
  * Fixed - compatibility issues with WP 4.2.x
39
 
4
  Tags: category, filter, taxonomy, search, wordpress, post type, post date
5
  Requires at least: 3.5
6
  Tested up to: 4.2.1
7
+ Stable tag: 1.2.7
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.7 =
38
+ * Fixed - fix for new taxonomy rewrites and problems with multiple selection when using checkboxes
39
+ * Fixed - added previously hidden `multiselect` field type
40
+
41
  = 1.2.6 =
42
  * Fixed - compatibility issues with WP 4.2.x
43
 
search-filter.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.designsandcode.com/447/wordpress-search-filter-plugin-for
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.6
9
  Text Domain: searchandfilter
10
  License: GPLv2
11
  */
@@ -16,7 +16,7 @@ License: GPLv2
16
  * Set up Plugin Globals
17
  */
18
  if (!defined('SEARCHANDFILTER_VERSION_NUM'))
19
- define('SEARCHANDFILTER_VERSION_NUM', '1.2.6');
20
 
21
  if (!defined('SEARCHANDFILTER_THEME_DIR'))
22
  define('SEARCHANDFILTER_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
@@ -638,6 +638,8 @@ if ( ! class_exists( 'SearchAndFilter' ) )
638
  }
639
  }
640
 
 
 
641
  /* CATEGORIES */
642
  if((isset($_POST[SF_FPRE.'category']))&&($this->has_form_posted))
643
  {
@@ -689,7 +691,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
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' );
@@ -707,52 +709,18 @@ if ( ! class_exists( 'SearchAndFilter' ) )
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
  {
@@ -803,7 +771,132 @@ if ( ! class_exists( 'SearchAndFilter' ) )
803
  }
804
 
805
  $tags = implode($operator,$tagarr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
807
  if(!$this->hasqmark)
808
  {
809
  $this->urlparams .= "?";
@@ -813,11 +906,30 @@ if ( ! class_exists( 'SearchAndFilter' ) )
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))
@@ -847,23 +959,6 @@ if ( ! class_exists( 'SearchAndFilter' ) )
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
 
@@ -955,88 +1050,6 @@ if ( ! class_exists( 'SearchAndFilter' ) )
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
 
@@ -1057,6 +1070,7 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1057
  }
1058
 
1059
  wp_redirect((home_url().$this->urlparams));
 
1060
  }
1061
  }
1062
 
@@ -1287,7 +1301,6 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1287
  }
1288
  else if($types[$i]=="checkbox")
1289
  {
1290
-
1291
  $returnvar .= $this->generate_checkbox($taxonomychildren, $field, $this->tagid);
1292
  }
1293
  else if($types[$i]=="radio")
@@ -1397,9 +1410,9 @@ if ( ! class_exists( 'SearchAndFilter' ) )
1397
  $args['title_li'] = '';
1398
  $args['defaults'] = "";
1399
 
1400
- if(isset($this->defaults[$args['name']]))
1401
  {
1402
- $args['defaults'] = $this->defaults[$args['name']];
1403
  }
1404
 
1405
  $returnvar .= $this->generate_wp_multiselect($args, $taxonomy, $this->tagid, $taxonomydata->labels);
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.7
9
  Text Domain: searchandfilter
10
  License: GPLv2
11
  */
16
  * Set up Plugin Globals
17
  */
18
  if (!defined('SEARCHANDFILTER_VERSION_NUM'))
19
+ define('SEARCHANDFILTER_VERSION_NUM', '1.2.7');
20
 
21
  if (!defined('SEARCHANDFILTER_THEME_DIR'))
22
  define('SEARCHANDFILTER_THEME_DIR', ABSPATH . 'wp-content/themes/' . get_template());
638
  }
639
  }
640
 
641
+ $taxcount = 0;
642
+
643
  /* CATEGORIES */
644
  if((isset($_POST[SF_FPRE.'category']))&&($this->has_form_posted))
645
  {
691
 
692
  $categories = implode($operator,$catarr);
693
 
694
+ if(get_option('permalink_structure')&&($taxcount==0))
695
  {
696
  //$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
697
  $category_base = (get_option( 'category_base' )=="") ? "category" : get_option( 'category_base' );
709
  {
710
  $this->urlparams .= "&";
711
  }
712
+
713
  $this->urlparams .= "category_name=".$categories;
714
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
 
716
+ $taxcount++;
 
 
 
 
 
 
 
 
 
 
717
  }
718
+
719
+
720
  }
721
 
722
+
723
+
724
  /* TAGS */
725
  if((isset($_POST[SF_FPRE.'post_tag']))&&($this->has_form_posted))
726
  {
771
  }
772
 
773
  $tags = implode($operator,$tagarr);
774
+
775
+ if(get_option('permalink_structure')&&($taxcount==0))
776
+ {
777
+ $tag_path = "tag/".$tags."/";
778
+ $this->urlparams .= $tag_path;
779
+ }
780
+ else
781
+ {
782
+ if(!$this->hasqmark)
783
+ {
784
+ $this->urlparams .= "?";
785
+ $this->hasqmark = true;
786
+ }
787
+ else
788
+ {
789
+ $this->urlparams .= "&";
790
+ }
791
+ $this->urlparams .= "tag=".$tags;
792
+ }
793
+
794
+ $taxcount++;
795
+ }
796
+ }
797
+
798
+ //now we have dealt with the all the special case fields - search, tags, categories, post_types, post_date
799
+
800
+ //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
801
+ if($this->has_form_posted)
802
+ {
803
+ foreach($_POST as $key=>$val)
804
+ {
805
+ if(!in_array($key, $this->frmreserved))
806
+ {//if the key is not in the reserved array (ie, on a custom taxonomy - not tags, categories, search term, post type & post date)
807
+
808
+ // strip off all prefixes for custom fields - we just want to do a redirect - no processing
809
+ if (strpos($key, SF_FPRE) === 0)
810
+ {
811
+ $key = substr($key, strlen(SF_FPRE));
812
+ }
813
 
814
+ $the_post_tax = $val;
815
+
816
+
817
+ //make the post an array for easy looping
818
+ if(!is_array($val))
819
+ {
820
+ $post_tax[] = $the_post_tax;
821
+ }
822
+ else
823
+ {
824
+ $post_tax = $the_post_tax;
825
+ }
826
+ $taxarr = array();
827
+
828
+ foreach ($post_tax as $tax)
829
+ {
830
+ $tax = esc_attr($tax);
831
+ $taxobj = get_term_by('id',$tax,$key);
832
+
833
+ if(isset($taxobj->slug))
834
+ {
835
+ $taxarr[] = $taxobj->slug;
836
+ }
837
+ }
838
+
839
+ if(count($taxarr)>0)
840
+ {
841
+ $operator = "+"; //default behaviour
842
+
843
+ //check to see if an operator has been specified - only applies with fields that use multiple selects such as checkboxes or multi selects
844
+ if(isset($_POST[SF_FPRE.$key.'_operator']))
845
+ {
846
+ if($_POST[SF_FPRE.$key.'_operator']=="and")
847
+ {
848
+ $operator = "+";
849
+ }
850
+ else if($_POST[SF_FPRE.$key.'_operator']=="or")
851
+ {
852
+ $operator = ",";
853
+ }
854
+ else
855
+ {
856
+ $operator = "+";
857
+ }
858
+ }
859
+
860
+ $taxs = implode($operator,$taxarr);
861
+
862
+ //**due to some new wierd rewrite in WordPress, the first taxonomy which get rewritten to /taxonomyname/taxonomyvalue only uses the first value of an array - so do it manually
863
+ if(get_option('permalink_structure')&&($taxcount==0))
864
+ {
865
+ $tax_path = $key."/".$taxs."/";
866
+ $this->urlparams .= $tax_path;
867
+ }
868
+ else
869
+ {
870
+ if(!$this->hasqmark)
871
+ {
872
+ $this->urlparams .= "?";
873
+ $this->hasqmark = true;
874
+ }
875
+ else
876
+ {
877
+ $this->urlparams .= "&";
878
+ }
879
+ $this->urlparams .= $key."=".$taxs;
880
+ }
881
+
882
+ $taxcount++;
883
+
884
+ }
885
+ }
886
+ }
887
+
888
+
889
+ }
890
+
891
+
892
+
893
+ /* SEARCH BOX */
894
+ if((isset($_POST[SF_FPRE.'search']))&&($this->has_form_posted))
895
+ {
896
+ $this->searchterm = trim(stripslashes($_POST[SF_FPRE.'search']));
897
+
898
+ if($this->searchterm!="")
899
+ {
900
  if(!$this->hasqmark)
901
  {
902
  $this->urlparams .= "?";
906
  {
907
  $this->urlparams .= "&";
908
  }
909
+ $this->urlparams .= "s=".urlencode($this->searchterm);
910
+ $this->hassearchquery = true;
911
+ }
912
+ }
913
+ if(!$this->hassearchquery)
914
+ {
915
+
916
+ if((isset($_POST[SF_FPRE.'add_search_param']))&&($this->has_form_posted))
917
+ {//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
918
+
919
+
920
+
921
+ if(!$this->hasqmark)
922
+ {
923
+ $this->urlparams .= "?";
924
+ $this->hasqmark = true;
925
+ }
926
+ else
927
+ {
928
+ $this->urlparams .= "&";
929
+ }
930
+ $this->urlparams .= "s=";
931
  }
932
  }
 
933
 
934
  /* POST TYPES */
935
  if((isset($_POST[SF_FPRE.'post_types']))&&($this->has_form_posted))
959
  if(count($post_types_arr)>0)
960
  {
961
  $operator = ","; //default behaviour
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
962
 
963
  $post_types = implode($operator,$post_types_arr);
964
 
1050
  }
1051
  }
1052
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1053
  if($this->has_form_posted)
1054
  {//if the search has been posted, redirect to the newly formed url with all the right params
1055
 
1070
  }
1071
 
1072
  wp_redirect((home_url().$this->urlparams));
1073
+ exit;
1074
  }
1075
  }
1076
 
1301
  }
1302
  else if($types[$i]=="checkbox")
1303
  {
 
1304
  $returnvar .= $this->generate_checkbox($taxonomychildren, $field, $this->tagid);
1305
  }
1306
  else if($types[$i]=="radio")
1410
  $args['title_li'] = '';
1411
  $args['defaults'] = "";
1412
 
1413
+ if(isset($this->defaults[$args['sf_name']]))
1414
  {
1415
+ $args['defaults'] = $this->defaults[$args['sf_name']];
1416
  }
1417
 
1418
  $returnvar .= $this->generate_wp_multiselect($args, $taxonomy, $this->tagid, $taxonomydata->labels);