Advertisement
Guest User

Untitled

a guest
Sep 26th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.58 KB | None | 0 0
  1. <?php
  2. /**
  3. * The template for displaying search results pages.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
  6. *
  7. * @package outdoorchef
  8. */
  9.  
  10. get_header(); ?>
  11.  
  12. <div id="primary" class="content-area">
  13. <main id="main" class="site-main" role="main">
  14. <form role="search" class="form_search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
  15. <div class="form_search_content">
  16. <input type="text" name="s" id="s" <?php if(is_search()) { ?>value="<?php the_search_query(); ?>" <?php } else { ?>value="Enter keywords &hellip;" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"<?php } ?> />
  17. </div>
  18.  
  19. <?php
  20. $query_types = $_GET['post_type'];
  21. $query_tax = get_query_var('taxonomy');
  22. ?>
  23.  
  24. <div class="form_search_attributes">
  25. <span><?php _e('Filters:', 'outdoorchef'); ?></span>
  26.  
  27. <div class="form_checkbox_item">
  28. <input type="checkbox" name="taxonomy[]" id="catgrill" value="Grill" <?php if (in_array('Grill', $query_tax)) { echo 'checked="checked"'; } ?> />
  29. <label for="catgrill"><?php _e('Grills', 'outdoorchef'); ?></label>
  30. </div>
  31. <div class="form_checkbox_item">
  32. <input type="checkbox" name="taxonomy[]" id="cataccessories" value="Accessories" <?php if (in_array('Accessories', $query_tax)) { echo 'checked="checked"'; } ?> />
  33. <label for="cataccessories"><?php _e('Accessories', 'outdoorchef'); ?></label>
  34. </div>
  35. <div class="form_checkbox_item">
  36. <input type="checkbox" name="taxonomy[]" id="catclass" value="Event" <?php if (in_array('Event', $query_tax)) { echo 'checked="checked"'; } ?> />
  37. <label for="catclass"><?php _e('Cooking classes', 'outdoorchef'); ?></label>
  38. </div>
  39. <div class="form_checkbox_item">
  40. <input type="checkbox" name="post_type[]" id="typerecipe" value="outdoorchefrecipe" <?php if (in_array('outdoorchefrecipe', $query_types)) { echo 'checked="checked"'; } ?> />
  41. <label for="typerecipe"><?php _e('Recipes', 'outdoorchef'); ?></label>
  42. </div>
  43. <div class="form_checkbox_item">
  44. <input type="checkbox" name="post_type[]" id="typepage" value="page" <?php if (in_array('page', $query_types)) { echo 'checked="checked"'; } ?> />
  45. <label for="typepage"><?php _e('Others', 'outdoorchef'); ?></label>
  46. </div>
  47. <button class="btn btn_apply_filter" type="submit" id="searchsubmit" role="button"><?php _e('Apply filter', 'outdoorchef'); ?></button>
  48. </div>
  49. </form>
  50.  
  51. <?php
  52.  
  53. $tax_types = [];
  54.  
  55. $taxs = get_query_var('taxonomy');
  56.  
  57. if(is_array($taxs)) {
  58. if( in_array('Grill', $taxs)) {
  59. array_push($tax_types, 'Grill');
  60. }
  61. if( in_array('Accessories', $taxs)) {
  62. array_push($tax_types, 'Accessories');
  63. }
  64. if( in_array('Event', $taxs)) {
  65. array_push($tax_types, 'Event');
  66. }
  67. }
  68.  
  69. $post_types = [];
  70.  
  71.  
  72. $posts = isset( $_GET["post_type"] ) ? $_GET["post_type"] : "";
  73.  
  74. if(is_array($posts)) {
  75. if( in_array('outdoorchefrecipe', $posts)) {
  76. array_push($post_types, 'outdoorchefrecipe');
  77. }
  78.  
  79. if( in_array('page', $posts)) {
  80. array_push($post_types, 'page');
  81. }
  82. }
  83.  
  84. $base = get_bloginfo('url');
  85.  
  86. $count_param = count(explode('&', $_SERVER['QUERY_STRING']));
  87.  
  88. if ($count_param === 2) {
  89. $hide_remaining = 'hideremaining';
  90. $hide_grid = '';
  91. }else{
  92. $hide_remaining = '';
  93. $hide_grid = 'hidegrid';
  94. }
  95.  
  96. echo '<div class="search-content">';
  97. foreach ( $tax_types as $tax_type ) {
  98. $s = isset( $_GET["s"] ) ? $_GET["s"] : "";
  99. // accepts any wp_query args.
  100.  
  101. $targs = (array(
  102. 's' => $s,
  103. 'post_status' => 'publish',
  104. 'post_type' => 'product',
  105. 'posts_per_page' => -1,
  106. 'tax_query' => array(
  107. array(
  108. 'taxonomy' => 'product_cat',
  109. 'field' => 'name',
  110. 'terms' => $tax_type,
  111. ),
  112. ),
  113. ));
  114.  
  115. $tquery = new WP_Query( $targs );
  116. if ( $tquery->have_posts() ) {
  117. if ($tax_type == 'Grill') {
  118. $header = __('Grills', 'outdoorchef');
  119. }elseif ($tax_type == 'Accessories') {
  120. $header = __('Accessories', 'outdoorchef');
  121. }
  122. elseif ($tax_type == 'Event') {
  123. $header = __('Events', 'outdoorchef');
  124. }
  125. echo '<div class="post-type '. $tax_type . '"><div class="post-type-heading">'. $header . '</div><div class="row odc_accessories_cat">';
  126. while( $tquery->have_posts() ){
  127. $tquery->the_post();
  128. if( $tax_type == 'Grill' ){ ?>
  129. <div class="col-lg-3 col-sm-4 col-xs-12 grid-item <?php echo $hide_grid; ?>">
  130. <div class="remaining-posts <?php echo $hide_remaining; ?>">
  131. <a href="<?php echo $base.'/?s='.$s.'&taxonomy%5B%5D=Grill' ?>">
  132. <?php
  133. $total_posts = $tquery->found_posts;
  134. $remaining = $total_posts - 3;
  135. ?>
  136. <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
  137.  
  138. </a>
  139. </div>
  140. <div class="odc-acries-item">
  141. <a href="<?php echo get_the_permalink(); ?>">
  142. <div class="odc_acries_image subaccessories">
  143. <?php if ( has_post_thumbnail() ) the_post_thumbnail('odc_featured_product', array('class' => 'img-responsvie')) ?>
  144. </div>
  145. <div class="grill-cat-img">
  146. <?php
  147. $terms = get_the_terms ( $product_id, 'product_cat' ) ;
  148. $term = $terms[1];
  149. $sub_cat_name = $term->name;
  150. ?>
  151. <?php if (($sub_cat_name == 'Gas') || ($sub_cat_name == 'Australian') ) { ?>
  152. <img src="<?php echo get_template_directory_uri(); ?>/assets/images/icon/gas-aus.png" class="img-responsive category" alt="category">
  153. <?php } ?>
  154. <?php if ($sub_cat_name == ' Charcole') { ?>
  155. <img src="<?php echo get_template_directory_uri(); ?>/assets/images/icon/charcoal.png" class="img-responsive category" alt="category">
  156. <?php } ?>
  157. <?php if ($sub_cat_name == 'Electric') { ?>
  158. <img src="<?php echo get_template_directory_uri(); ?>/assets/images/icon/electric.png" class="img-responsive category" alt="category">
  159. <?php } ?>
  160. </div>
  161. <div class="odc-acries-desc">
  162. <h4><?php the_title(); ?></h4>
  163. </div>
  164. </a>
  165. </div>
  166. </div>
  167. <?php }
  168. if( $tax_type == 'Accessories' ){ ?>
  169. <div class="col-lg-3 col-sm-4 col-xs-12 grid-item <?php echo $hide_grid; ?>">
  170. <div class="remaining-posts <?php echo $hide_remaining; ?>">
  171. <a href="<?php echo $base.'/?s='.$s.'&taxonomy%5B%5D=Accessories' ?>">
  172. <?php
  173. $total_posts = $tquery->found_posts;
  174. $remaining = $total_posts - 3;
  175. ?>
  176. <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
  177. </a>
  178. </div>
  179. <div class="odc-acries-item">
  180. <a href="<?php echo get_the_permalink(); ?>">
  181. <div class="odc_acries_image subaccessories">
  182. <?php if ( has_post_thumbnail() ) the_post_thumbnail('odc_featured_product', array('class' => 'img-responsvie')) ?>
  183. </div>
  184. <div class="odc-acries-desc">
  185. <h4><?php the_title(); ?></h4>
  186. <span class="price"><?php echo $product->get_price_html() ?></span>
  187. </div>
  188. </a>
  189. </div>
  190. </div>
  191. <?php }
  192. if( $tax_type == 'Event' ){
  193. $event_date = get_post_meta(get_the_ID(), 'odc_event_date', true );
  194. $event_date = strtotime($event_date);
  195. $today = date('Y-m-d');
  196. $today = strtotime($today);
  197. if ($event_date > $today) { ?>
  198. <div class="col-lg-3 col-sm-4 col-xs-12 grid-item <?php echo $hide_grid; ?>">
  199. <div class="remaining-posts <?php echo $hide_remaining; ?>">
  200. <a href="<?php echo $base.'/?s='.$s.'&taxonomy%5B%5D=Event' ?>">
  201. <?php
  202. $total_posts = $tquery->found_posts;
  203. $remaining = $total_posts - 3;
  204. ?>
  205. <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
  206. </a>
  207. </div>
  208. <div class="odc-acries-item">
  209. <a href="<?php echo get_the_permalink(); ?>">
  210. <div class="odc_acries_image subaccessories">
  211. <?php if ( has_post_thumbnail() ){
  212. the_post_thumbnail('odc_featured_product', array('class' => 'img-responsvie'));
  213. } ?>
  214. </div>
  215. <div class="odc-acries-desc">
  216. <h4><?php the_title(); ?></h4>
  217. <span class="price"><?php echo $product->get_price_html() ?></span>
  218. <p class="event-date"><?php echo date_i18n('F j, Y', strtotime(get_field('odc_event_date', $post->ID, false))); ?>, <?php echo date_i18n('H:i', strtotime(get_field('odc_event_start_time', $post->ID, false))); ?></p>
  219. <p class="event-day"><?php echo date_i18n('l', strtotime(get_field('odc_event_date', $post->ID, false))); ?></p>
  220. </div>
  221. </a>
  222. </div>
  223. </div>
  224. <?php } }
  225. }
  226. echo "</div></div>";
  227. }
  228. wp_reset_query();
  229. }
  230. foreach ( $post_types as $post_type ) {
  231. $s = isset( $_GET["s"] ) ? $_GET["s"] : "";
  232. // accepts any wp_query args.
  233. $args = (array(
  234. 's' => $s,
  235. 'post_type' => $post_type,
  236. 'post_status' => 'publish',
  237. 'posts_per_page' => -1
  238. ));
  239.  
  240. $query = new WP_Query( $args );
  241. if ( $query->have_posts() ) {
  242. if ($post_type == 'outdoorchefrecipe') {
  243. $row_class="all-recipe";
  244. $header = __('Recipes', 'outdoorchef');
  245. }elseif ($post_type == 'page') {
  246. $row_class="all-recipe";
  247. $header = __('Others', 'outdoorchef');
  248. }
  249. echo '<div class="post-type '. $post_type .'"><div class="post-type-heading">'. $header . '</div><div class="row '.$row_class.'">';
  250.  
  251. while( $query->have_posts() ){
  252. $query->the_post();
  253.  
  254. if( $post_type == 'outdoorchefrecipe' ){ ?>
  255. <div class="col-xs-12 col-sm-6 col-md-3 grid-item all <?php echo $hide_grid; ?>">
  256. <div class="remaining-posts <?php echo $hide_remaining; ?>">
  257. <a href="<?php echo $base.'/?s='.$s.'&post_type%5B%5D=outdoorchefrecipe' ?>">
  258. <?php
  259. $total_posts = $query->found_posts;
  260. $remaining = $total_posts - 3;
  261. ?>
  262. <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
  263. </a>
  264. </div>
  265. <a href="<?php the_permalink(); ?>">
  266. <div class="recipe-item">
  267. <div class="recipe-item-wrap">
  268. <?php if( has_post_thumbnail() ) the_post_thumbnail(array(262, 208), ['class' => 'img-responsive']); ?>
  269. <div class="overlay">
  270. <div class="recipe-item-inner">
  271. <span class="preview" href=""><?php _e('View Details', 'outdoorchef'); ?></span>
  272. </div>
  273. </div>
  274. </div>
  275.  
  276. <div class="recipe-item-info text-center">
  277. <h3 class="recipe-filter-title"><?php the_title(); ?></h3>
  278. </div>
  279. </div>
  280. </a>
  281. <!-- <div class="recipe-space"></div> -->
  282. </div>
  283. <?php }
  284. if( $post_type == 'page' ){ ?>
  285. <div class="col-md-6 pages-search grid-item <?php echo $hide_grid; ?>">
  286. <div class="remaining-posts <?php echo $hide_remaining; ?>">
  287. <a href="<?php echo $base.'/?s='.$s.'&post_type%5B%5D=page' ?>">
  288. <?php
  289. $total_posts = $query->found_posts;
  290. $remaining = $total_posts - 3;
  291. ?>
  292. <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
  293. </a>
  294. </div>
  295. <a href="<?php the_permalink(); ?>">
  296. <div class="tile_box">
  297. <h4 class="tile_content_title"><?php the_title(); ?></h4>
  298. <p class="tile_content_url"><?php the_permalink(); ?></p>
  299. <p class="tile_content_desc"><?php the_excerpt(); ?></p>
  300. </div>
  301. </a>
  302. </div>
  303. <?php }
  304. }
  305.  
  306. echo '</div></div>';
  307. }
  308. }
  309. if ( (!$tquery->have_posts()) && (!$query->have_posts()) ) { ?>
  310. <h2 class="no-result-found"><?php echo __("We could not find a match for ", "outdoorchef-search").'\''.$s.'\''.__('&nbsp;', 'outdoorchef-search') ?></h2>
  311. <h2 class="no-result-found"><?php echo __('Please try another term', 'outdoorchef-search') ?></h2>
  312. <?php }
  313. echo '</div><br>'; // .search-content
  314. ?>
  315.  
  316. </main><!-- #main -->
  317. </div><!-- #primary -->
  318.  
  319. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement