PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.9.21
Shortcodes and extra features for Phlox theme v2.9.21
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 4 years ago class-auxels-archive-menu-links.php 4 years ago class-auxels-envato-elements.php 4 years ago class-auxels-import-parser.php 4 years ago class-auxels-import.php 3 years ago class-auxels-search-post-type.php 4 years ago class-auxels-wc-attribute-nav-menu.php 4 years ago class-auxin-admin-dashboard.php 4 years ago class-auxin-demo-importer.php 3 years ago class-auxin-dependency-sorting.php 4 years ago class-auxin-import.php 4 years ago class-auxin-install.php 4 years ago class-auxin-master-nav-menu-admin.php 3 years ago class-auxin-page-template.php 4 years ago class-auxin-permalink.php 3 years ago class-auxin-plugin-requirements.php 4 years ago class-auxin-post-type-base.php 4 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 4 years ago class-auxin-walker-nav-menu-back.php 4 years ago class-auxin-welcome-sections.php 3 years ago class-auxin-welcome.php 3 years ago class-auxin-whitelabel.php 4 years ago class-auxin-widget-indie.php 4 years ago class-auxin-widget-shortcode-map.php 4 years ago class-auxin-widget.php 3 years ago
class-auxels-search-post-type.php
319 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-2022 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 public 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 $this->set_query_args($product_args);
132 // Search all product for sku meta fields
133 $sku_args = array(
134 's' => '',
135 'meta_query' => array(
136 array(
137 'key' => '_sku',
138 'value' => $this->s,
139 'compare' => 'like',
140 ),
141 ),
142 'suppress_filters' => 0,
143 );
144
145 $this->set_query_args( $sku_args );
146 $search_products_for_sku = $this->search();
147
148 // Search All Variations for sku meta field
149 $this->set_query_args($product_variation_args);
150 $search_variations_for_sku = $this->search();
151
152 //set search phrase query argument after searching for sku without search phrase
153 $this->set_query_args( array( 's' => $this->s ) );
154
155 // Merge All search results and remove the same results
156 $all_search_results = array_merge(
157 $search_products_for_sku->posts,
158 $search_variations_for_sku->posts,
159 $search_products_for_name->posts
160 );
161
162 $products_id = array();
163 foreach ($all_search_results as $key => $product) {
164 $id = $product->ID;
165 if ( in_array( $id, $products_id) ) {
166 unset( $all_search_results[$key] );
167 } else {
168 $products_id[] = $id;
169 }
170 }
171
172 // Generate output dom
173 if ( !empty( $all_search_results ) ) {
174 global $post;
175 foreach ( $all_search_results as $post ) {
176 setup_postdata( $post );
177 $product = wc_get_product( get_the_ID() );
178 $categories = get_the_terms( $product->get_id(), 'product_cat' );
179 $cat = $categories[0]->name;
180 $results[] = sprintf(
181 $this->search_item_wrapper_start.
182 $this->search_item_container_start.
183 '%s'.
184 $this->search_item_description_start.
185 $this->search_item_title_start.
186 '%s'.
187 $this->search_item_title_end.
188 $this->search_item_details_start.
189 '%s'.
190 $this->search_item_details_end.
191 '%s'.
192 $this->search_item_description_end.
193 $this->search_item_container_end.
194 $this->search_item_wrapper_end,
195 'product',
196 get_permalink(),
197 ( ( has_post_thumbnail() ) ? woocommerce_get_product_thumbnail( 'shop_thumbnail' ) : '' ),
198 $product->get_title(),
199 $cat,
200 "<span class='aux-price'>".$product->get_price_html()."</span>"
201 );
202 }
203 unset($this->query_args['meta_query']);
204 unset($this->query_args['suppress_filters']);
205 wp_reset_postdata();
206
207 return $this->search_results( 'product', $results);
208
209 } else {
210
211 unset($this->query_args['meta_query']);
212 unset($this->query_args['suppress_filters']);
213
214 return $this->search_results( 'product' );
215 }
216 }
217
218 /**
219 * Search General Post types
220 *
221 * @return string
222 */
223 public function search_general_post_types() {
224 $search_result = $this->search();
225 if ($search_result->have_posts()) {
226 global $post;
227 while($search_result->have_posts()) {
228 $search_result->the_post();
229 $results[] = sprintf(
230 $this->search_item_wrapper_start.
231 $this->search_item_container_start.
232 '<img src="%s">'.
233 $this->search_item_description_start.
234 $this->search_item_title_start.
235 '%s'.
236 $this->search_item_title_end.
237 $this->search_item_details_start.
238 '%s'.
239 $this->search_item_details_end.
240 $this->search_item_description_end.
241 $this->search_item_container_end.
242 $this->search_item_wrapper_end,
243 'blog',
244 get_permalink(),
245 get_the_post_thumbnail_url(),
246 get_the_title(),
247 get_the_date()
248 );
249 }
250 wp_reset_postdata();
251 return $this->search_results( $this->query_args['post_type'], $results );
252 } else {
253 return $this->search_results( $this->query_args['post_type'] );
254 }
255 }
256
257 /**
258 * Search Portfolio Post type
259 *
260 * @return string
261 */
262 public function search_portfolio() {
263 $search_result = $this->search();
264
265 if ( $search_result->have_posts() ) {
266 global $post;
267 while ( $search_result->have_posts() ) {
268 $search_result->the_post();
269 $results[] = sprintf(
270 $this->search_item_wrapper_start.
271 $this->search_item_container_start.
272 '<img src="%s">'.
273 $this->search_item_container_end.
274 $this->search_item_wrapper_end,
275 'portfolio',
276 get_permalink(),
277 get_the_post_thumbnail_url()
278 );
279 }
280 wp_reset_postdata();
281
282 return $this->search_results( 'portfloio', $results );
283 } else {
284 return $this->search_results( 'portfolio' );
285 }
286 }
287
288 /**
289 * Main Query Method
290 */
291 public function search() {
292 $search_result = new WP_Query( $this->query_args );
293 return $search_result;
294 }
295
296 /**
297 * Return Search results as array
298 *
299 * @param string $post_type
300 * @param array $results
301 *
302 * @return array
303 */
304 public function search_results( $post_type = 'post', $results = array() ) {
305 return array(
306 'postType' => $post_type,
307 'results' => $results,
308 'searchLink' => add_query_arg(
309 array(
310 's' => $this->s,
311 'post_type' => $post_type
312 ),
313 get_site_url()
314 )
315 );
316 }
317
318 }
319