PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.5.8
Shortcodes and extra features for Phlox theme v2.5.8
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / classes / class-auxels-search-post-type.php
auxin-elements / includes / classes Last commit date
class-auxels-admin-assets.php 6 years ago class-auxels-archive-menu-links.php 6 years ago class-auxels-import-parser.php 8 years ago class-auxels-import.php 6 years ago class-auxels-search-post-type.php 6 years ago class-auxin-admin-dashboard.php 6 years ago class-auxin-demo-importer.php 6 years ago class-auxin-dependency-sorting.php 8 years ago class-auxin-import.php 6 years ago class-auxin-install.php 6 years ago class-auxin-master-nav-menu-admin.php 6 years ago class-auxin-page-template.php 6 years ago class-auxin-permalink.php 6 years ago class-auxin-plugin-requirements.php 6 years ago class-auxin-post-type-base.php 6 years ago class-auxin-siteorigin-widget.php 6 years ago class-auxin-svg-support-allowedattributes.php 7 years ago class-auxin-svg-support-allowedtags.php 7 years ago class-auxin-svg-support.php 7 years ago class-auxin-walker-nav-menu-back.php 6 years ago class-auxin-welcome-sections.php 6 years ago class-auxin-welcome.php 6 years ago class-auxin-whitelabel.php 6 years ago class-auxin-widget-indie.php 6 years ago class-auxin-widget-shortcode-map.php 6 years ago class-auxin-widget.php 6 years ago
class-auxels-search-post-type.php
324 lines
1 <?php
2 /**
3 * Search Post Type Class.
4 *
5 *
6 * @package Auxin
7 * @license LICENSE.txt
8 * @author averta
9 * @link http://phlox.pro/
10 * @copyright (c) 2010-2020 averta
11 */
12
13 // no direct access allowed
14 if ( ! defined('ABSPATH') ) {
15 die();
16 }
17
18 /**
19 * Class to handle searching post types
20 */
21 class Auxels_Search_Post_Type {
22
23 /**
24 * Search Phrase
25 *
26 * @var string
27 */
28 public $s;
29
30 /**
31 * Search category
32 *
33 * @var string
34 */
35 public $cat;
36
37 /**
38 * Search Post Type
39 *
40 * @var string
41 */
42 public $post_type;
43
44 /**
45 * Number of serach Items per page
46 *
47 * @var string
48 */
49 public $per_page;
50
51 /**
52 * Search query args
53 *
54 * @var array
55 */
56 public $query_args = array();
57
58 public $search_item_wrapper_start = "<div class='aux-search-item %s'>";
59 public $search_item_container_start = "<a href='%s' class='aux-item-container'>";
60 public $search_item_description_start = "<span class='aux-item-desc'>";
61 public $search_item_title_start = "<span class='aux-item-title'>";
62 public $search_item_details_start = "<span class='aux-item-details'>";
63
64 public $search_item_details_end = "</span>";
65 public $search_item_title_end = "</span>";
66 public $search_item_description_end = "</span>";
67 public $search_item_container_end = "</a>";
68 public $search_item_wrapper_end = "</div>";
69
70 /**
71 * __construct
72 */
73 function __construct( $search_phrase = '', $search_category = '', $search_post_type = '', $number_per_page = '' ) {
74
75 $this->s = $search_phrase;
76 $this->cat = $search_category;
77 $this->post_type = $search_post_type;
78 $this->per_page = $number_per_page;
79
80 $query_args = array (
81 's' => $this->s,
82 'post_type' => $this->post_type,
83 'no_found_rows' => 1,
84 'posts_per_page' => $this->per_page
85 );
86
87 // Get category slug for each post type
88
89 $categories_slug = auxin_general_post_types_category_slug();
90 if ( !empty( $this->cat ) ) {
91 $query_args['tax_query'] = array(
92 array(
93 'taxonomy' => $categories_slug[$this->post_type],
94 'field' => 'slug',
95 'terms' => array( $this->cat )
96 )
97 );
98 }
99 $this->set_query_args($query_args);
100 }
101
102 /**
103 * Change Query Args - append or modify query args parameter
104 *
105 * @return void
106 */
107 public function set_query_args ($args = array()) {
108 if ( !empty( $args ) ) {
109 foreach ( $args as $key => $value ) {
110 $this->query_args[$key] = $value;
111 }
112 }
113 }
114
115 /**
116 * Search Products Post type
117 *
118 * @return string
119 */
120 public function search_products() {
121
122 if ( !class_exists( 'WooCommerce' ) )
123 return;
124
125 $product_args = array( 'post_type' => 'product' );
126 $product_variation_args = array( 'post_type' => 'product_variation' );
127
128 // search all products
129 $search_products_for_name = $this->search();
130
131 // search all product variations
132 $this->set_query_args($product_variation_args);
133 $search_variations_for_name = $this->search();
134
135 $this->set_query_args($product_args);
136 // Search all product for sku meta fields
137 $sku_args = array(
138 's' => '',
139 'meta_query' => array(
140 array(
141 'key' => '_sku',
142 'value' => $this->s,
143 'compare' => 'like',
144 ),
145 ),
146 'suppress_filters' => 0,
147 );
148
149 $this->set_query_args( $sku_args );
150 $search_products_for_sku = $this->search();
151
152 // Search All Variations for sku meta field
153 $this->set_query_args($product_variation_args);
154 $search_variations_for_sku = $this->search();
155
156 //set search phrase query argument after searching for sku without search phrase
157 $this->set_query_args( array( 's' => $this->s ) );
158
159 // Merge All search results and remove the same results
160 $all_search_results = array_merge(
161 $search_products_for_sku->posts,
162 $search_variations_for_sku->posts,
163 $search_products_for_name->posts,
164 $search_variations_for_name->posts
165 );
166
167 $products_id = array();
168 foreach ($all_search_results as $key => $product) {
169 $id = $product->ID;
170 if ( in_array( $id, $products_id) ) {
171 unset( $all_search_results[$key] );
172 } else {
173 $products_id[] = $id;
174 }
175 }
176
177 // Generate output dom
178 if ( !empty( $all_search_results ) ) {
179 global $post;
180 foreach ( $all_search_results as $post ) {
181 setup_postdata( $post );
182 $product = wc_get_product( get_the_ID() );
183 $categories = get_the_terms( $product->get_id(), 'product_cat' );
184 $cat = $categories[0]->name;
185 $results[] = sprintf(
186 $this->search_item_wrapper_start.
187 $this->search_item_container_start.
188 '%s'.
189 $this->search_item_description_start.
190 $this->search_item_title_start.
191 '%s'.
192 $this->search_item_title_end.
193 $this->search_item_details_start.
194 '%s'.
195 $this->search_item_details_end.
196 '%s'.
197 $this->search_item_description_end.
198 $this->search_item_container_end.
199 $this->search_item_wrapper_end,
200 'product',
201 get_permalink(),
202 ( ( has_post_thumbnail() ) ? woocommerce_get_product_thumbnail( 'shop_thumbnail' ) : '' ),
203 $product->get_title(),
204 $cat,
205 "<span class='aux-price'>".$product->get_price_html()."</span>"
206 );
207 }
208 unset($this->query_args['meta_query']);
209 unset($this->query_args['suppress_filters']);
210 wp_reset_postdata();
211
212 return $this->search_results( 'product', $results);
213
214 } else {
215
216 unset($this->query_args['meta_query']);
217 unset($this->query_args['suppress_filters']);
218
219 return $this->search_results( 'product' );
220 }
221 }
222
223 /**
224 * Search General Post types
225 *
226 * @return string
227 */
228 public function search_general_post_types() {
229 $search_result = $this->search();
230 if ($search_result->have_posts()) {
231 global $post;
232 while($search_result->have_posts()) {
233 $search_result->the_post();
234 $results[] = sprintf(
235 $this->search_item_wrapper_start.
236 $this->search_item_container_start.
237 '<img src="%s">'.
238 $this->search_item_description_start.
239 $this->search_item_title_start.
240 '%s'.
241 $this->search_item_title_end.
242 $this->search_item_details_start.
243 '%s'.
244 $this->search_item_details_end.
245 $this->search_item_description_end.
246 $this->search_item_container_end.
247 $this->search_item_wrapper_end,
248 'blog',
249 get_permalink(),
250 get_the_post_thumbnail_url(),
251 get_the_title(),
252 get_the_date()
253 );
254 }
255 wp_reset_postdata();
256 return $this->search_results( $this->query_args['post_type'], $results );
257 } else {
258 return $this->search_results( $this->query_args['post_type'] );
259 }
260 }
261
262 /**
263 * Search Portfolio Post type
264 *
265 * @return string
266 */
267 public function search_portfolio() {
268 $search_result = $this->search();
269
270 if ( $search_result->have_posts() ) {
271 global $post;
272 while ( $search_result->have_posts() ) {
273 $search_result->the_post();
274 $results[] = sprintf(
275 $this->search_item_wrapper_start.
276 $this->search_item_container_start.
277 '<img src="%s">'.
278 $this->search_item_container_end.
279 $this->search_item_wrapper_end,
280 'portfolio',
281 get_permalink(),
282 get_the_post_thumbnail_url()
283 );
284 }
285 wp_reset_postdata();
286
287 return $this->search_results( 'portfloio', $results );
288 } else {
289 return $this->search_results( 'portfolio' );
290 }
291 }
292
293 /**
294 * Main Query Method
295 */
296 public function search() {
297 $search_result = new WP_Query( $this->query_args );
298 return $search_result;
299 }
300
301 /**
302 * Return Search results as array
303 *
304 * @param string $post_type
305 * @param array $results
306 *
307 * @return array
308 */
309 public function search_results( $post_type = 'post', $results = array() ) {
310 return array(
311 'postType' => $post_type,
312 'results' => $results,
313 'searchLink' => add_query_arg(
314 array(
315 's' => $this->s,
316 'post_type' => $post_type
317 ),
318 get_site_url()
319 )
320 );
321 }
322
323 }
324