Changeset 1460817
- Timestamp:
- 07/26/2016 12:52:53 PM (10 years ago)
- Location:
- acf-search/trunk
- Files:
-
- 2 edited
-
acf-search.php (modified) (8 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
acf-search/trunk/acf-search.php
r1460094 r1460817 5 5 Description: Adds the ability to search trough the selected ACF-fields 6 6 Author: Direct ICT B.V. 7 Version: 2.1. 47 Version: 2.1.5 8 8 Author URI: https://www.directict.nl/ 9 9 */ 10 10 11 11 // how da fuck -.- 12 global $acf_ fields;13 $acf_ fields = array();12 global $acf_search_fields; 13 $acf_search_fields = array(); 14 14 15 global $ plugin_data;15 global $acf_search_plugin_data; 16 16 17 function acf_search_init() { 18 global $acf_ fields;17 function acf_search_init() { 18 global $acf_search_fields; 19 19 $t=array(); 20 20 add_filter( 'posts_where' , 'posts_where_excerpt_not_empty' ); 21 21 $ACFFIELDS = new WP_Query( 22 array( 22 array( 23 23 "posts_per_page" => -1, 24 24 "post_type" => 'acf-field' … … 26 26 ); 27 27 remove_filter( 'posts_where' , 'posts_where_excerpt_not_empty' ); 28 28 29 29 while($ACFFIELDS->have_posts()) { 30 30 $ACFFIELDS->the_post(); 31 31 if(!in_array(get_the_excerpt(), $t)) { 32 if(get_the_excerpt()) { 33 $acf_ fields[] = (object)array("display" => get_the_title(), "return" => get_the_excerpt());32 if(get_the_excerpt()) { 33 $acf_search_fields[] = (object)array("display" => get_the_title(), "return" => get_the_excerpt()); 34 34 } 35 35 36 36 $t[] = get_the_excerpt(); 37 37 } … … 54 54 } 55 55 56 include __DIR__."/templates/options.php"; 56 include __DIR__."/templates/options.php"; 57 57 } 58 58 … … 68 68 // Register the options 69 69 add_option('acf_search_fields', serialize(array())); 70 71 // Load the plugin data into an global 72 global $ plugin_data;73 $ plugin_data = get_plugin_data( __FILE__ );70 71 // Load the plugin data into an global 72 global $acf_search_plugin_data; 73 $acf_search_plugin_data = get_plugin_data( __FILE__ ); 74 74 } 75 75 … … 78 78 * @return [array] [list of custom fields] 79 79 */ 80 function list_searcheable_acf(){81 $list_searcheable_acf = (unserialize(get_option('acf_search_fields'))); //array("title", "sub_title", "excerpt_short", "excerpt_long", "sub_content", "content");80 function acf_search_list_searcheable_acf(){ 81 $list_searcheable_acf = (unserialize(get_option('acf_search_fields'))); 82 82 return $list_searcheable_acf; 83 83 } … … 90 90 * credits to Vincent Zurczak for the base query structure/spliting tags section 91 91 */ 92 function a dvanced_custom_search( $where, &$wp_query ) {92 function acf_search_advanced_custom_search( $where, &$wp_query ) { 93 93 global $wpdb; 94 94 95 95 if ( empty( $where )) 96 96 return $where; 97 97 98 98 // get search expression 99 99 $terms = $wp_query->query_vars[ 's' ]; 100 100 101 101 // explode search expression to get search terms 102 102 $exploded = explode( ' ', $terms ); 103 103 if( $exploded === FALSE || count( $exploded ) == 0 ) 104 104 $exploded = array( 0 => $terms ); 105 105 106 106 // reset search in order to rebuilt it as we whish 107 107 $where = ''; 108 108 109 109 // get searcheable_acf, a list of advanced custom fields you want to search content in 110 $list_searcheable_acf = list_searcheable_acf(); 111 110 $list_searcheable_acf = acf_search_list_searcheable_acf(); 111 112 // If you did not select any custom fields we need to return the default Query 113 if(count($list_searcheable_acf) == 0) { 114 return $where; 115 } 116 112 117 foreach( $exploded as $tag ) : 113 118 114 119 $tag = esc_sql($wpdb->esc_like($tag)); 115 116 $where .= " 120 121 $where .= " 117 122 AND ( 118 123 (wp_posts.post_title LIKE '%{$tag}%') … … 144 149 WHERE ( 145 150 taxonomy = 'post_tag' 146 OR taxonomy = 'category' 151 OR taxonomy = 'category' 147 152 OR taxonomy = 'myCustomTax' 148 153 ) … … 155 160 return $where; 156 161 } 157 158 add_filter( 'posts_search', 'a dvanced_custom_search', 500, 2 );162 163 add_filter( 'posts_search', 'acf_search_advanced_custom_search', 500, 2 ); -
acf-search/trunk/readme.txt
r1460094 r1460817 29 29 == Changelog == 30 30 31 = 2.1.5 = 32 #2 When no CustomFields selected we return the default WP Search where-clause 33 31 34 = 2.1.4 = 32 Small change regarding the “plugin_data” function35 #1 Small change regarding the “plugin_data” function 33 36 34 37 = 2.1.3 =
Note: See TracChangeset
for help on using the changeset viewer.