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