Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * The template for displaying search results pages.
- *
- * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
- *
- * @package outdoorchef
- */
- get_header(); ?>
- <div id="primary" class="content-area">
- <main id="main" class="site-main" role="main">
- <form role="search" class="form_search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
- <div class="form_search_content">
- <input type="text" name="s" id="s" <?php if(is_search()) { ?>value="<?php the_search_query(); ?>" <?php } else { ?>value="Enter keywords …" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"<?php } ?> />
- </div>
- <?php
- $query_types = $_GET['post_type'];
- $query_tax = get_query_var('taxonomy');
- ?>
- <div class="form_search_attributes">
- <span><?php _e('Filters:', 'outdoorchef'); ?></span>
- <div class="form_checkbox_item">
- <input type="checkbox" name="taxonomy[]" id="catgrill" value="Grill" <?php if (in_array('Grill', $query_tax)) { echo 'checked="checked"'; } ?> />
- <label for="catgrill"><?php _e('Grills', 'outdoorchef'); ?></label>
- </div>
- <div class="form_checkbox_item">
- <input type="checkbox" name="taxonomy[]" id="cataccessories" value="Accessories" <?php if (in_array('Accessories', $query_tax)) { echo 'checked="checked"'; } ?> />
- <label for="cataccessories"><?php _e('Accessories', 'outdoorchef'); ?></label>
- </div>
- <div class="form_checkbox_item">
- <input type="checkbox" name="taxonomy[]" id="catclass" value="Event" <?php if (in_array('Event', $query_tax)) { echo 'checked="checked"'; } ?> />
- <label for="catclass"><?php _e('Cooking classes', 'outdoorchef'); ?></label>
- </div>
- <div class="form_checkbox_item">
- <input type="checkbox" name="post_type[]" id="typerecipe" value="outdoorchefrecipe" <?php if (in_array('outdoorchefrecipe', $query_types)) { echo 'checked="checked"'; } ?> />
- <label for="typerecipe"><?php _e('Recipes', 'outdoorchef'); ?></label>
- </div>
- <div class="form_checkbox_item">
- <input type="checkbox" name="post_type[]" id="typepage" value="page" <?php if (in_array('page', $query_types)) { echo 'checked="checked"'; } ?> />
- <label for="typepage"><?php _e('Others', 'outdoorchef'); ?></label>
- </div>
- <button class="btn btn_apply_filter" type="submit" id="searchsubmit" role="button"><?php _e('Apply filter', 'outdoorchef'); ?></button>
- </div>
- </form>
- <?php
- $tax_types = [];
- $taxs = get_query_var('taxonomy');
- if(is_array($taxs)) {
- if( in_array('Grill', $taxs)) {
- array_push($tax_types, 'Grill');
- }
- if( in_array('Accessories', $taxs)) {
- array_push($tax_types, 'Accessories');
- }
- if( in_array('Event', $taxs)) {
- array_push($tax_types, 'Event');
- }
- }
- $post_types = [];
- $posts = isset( $_GET["post_type"] ) ? $_GET["post_type"] : "";
- if(is_array($posts)) {
- if( in_array('outdoorchefrecipe', $posts)) {
- array_push($post_types, 'outdoorchefrecipe');
- }
- if( in_array('page', $posts)) {
- array_push($post_types, 'page');
- }
- }
- $base = get_bloginfo('url');
- $count_param = count(explode('&', $_SERVER['QUERY_STRING']));
- if ($count_param === 2) {
- $hide_remaining = 'hideremaining';
- $hide_grid = '';
- }else{
- $hide_remaining = '';
- $hide_grid = 'hidegrid';
- }
- echo '<div class="search-content">';
- foreach ( $tax_types as $tax_type ) {
- $s = isset( $_GET["s"] ) ? $_GET["s"] : "";
- // accepts any wp_query args.
- $targs = (array(
- 's' => $s,
- 'post_status' => 'publish',
- 'post_type' => 'product',
- 'posts_per_page' => -1,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'product_cat',
- 'field' => 'name',
- 'terms' => $tax_type,
- ),
- ),
- ));
- $tquery = new WP_Query( $targs );
- if ( $tquery->have_posts() ) {
- if ($tax_type == 'Grill') {
- $header = __('Grills', 'outdoorchef');
- }elseif ($tax_type == 'Accessories') {
- $header = __('Accessories', 'outdoorchef');
- }
- elseif ($tax_type == 'Event') {
- $header = __('Events', 'outdoorchef');
- }
- echo '<div class="post-type '. $tax_type . '"><div class="post-type-heading">'. $header . '</div><div class="row odc_accessories_cat">';
- while( $tquery->have_posts() ){
- $tquery->the_post();
- if( $tax_type == 'Grill' ){ ?>
- <div class="col-lg-3 col-sm-4 col-xs-12 grid-item <?php echo $hide_grid; ?>">
- <div class="remaining-posts <?php echo $hide_remaining; ?>">
- <a href="<?php echo $base.'/?s='.$s.'&taxonomy%5B%5D=Grill' ?>">
- <?php
- $total_posts = $tquery->found_posts;
- $remaining = $total_posts - 3;
- ?>
- <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
- </a>
- </div>
- <div class="odc-acries-item">
- <a href="<?php echo get_the_permalink(); ?>">
- <div class="odc_acries_image subaccessories">
- <?php if ( has_post_thumbnail() ) the_post_thumbnail('odc_featured_product', array('class' => 'img-responsvie')) ?>
- </div>
- <div class="grill-cat-img">
- <?php
- $terms = get_the_terms ( $product_id, 'product_cat' ) ;
- $term = $terms[1];
- $sub_cat_name = $term->name;
- ?>
- <?php if (($sub_cat_name == 'Gas') || ($sub_cat_name == 'Australian') ) { ?>
- <img src="<?php echo get_template_directory_uri(); ?>/assets/images/icon/gas-aus.png" class="img-responsive category" alt="category">
- <?php } ?>
- <?php if ($sub_cat_name == ' Charcole') { ?>
- <img src="<?php echo get_template_directory_uri(); ?>/assets/images/icon/charcoal.png" class="img-responsive category" alt="category">
- <?php } ?>
- <?php if ($sub_cat_name == 'Electric') { ?>
- <img src="<?php echo get_template_directory_uri(); ?>/assets/images/icon/electric.png" class="img-responsive category" alt="category">
- <?php } ?>
- </div>
- <div class="odc-acries-desc">
- <h4><?php the_title(); ?></h4>
- </div>
- </a>
- </div>
- </div>
- <?php }
- if( $tax_type == 'Accessories' ){ ?>
- <div class="col-lg-3 col-sm-4 col-xs-12 grid-item <?php echo $hide_grid; ?>">
- <div class="remaining-posts <?php echo $hide_remaining; ?>">
- <a href="<?php echo $base.'/?s='.$s.'&taxonomy%5B%5D=Accessories' ?>">
- <?php
- $total_posts = $tquery->found_posts;
- $remaining = $total_posts - 3;
- ?>
- <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
- </a>
- </div>
- <div class="odc-acries-item">
- <a href="<?php echo get_the_permalink(); ?>">
- <div class="odc_acries_image subaccessories">
- <?php if ( has_post_thumbnail() ) the_post_thumbnail('odc_featured_product', array('class' => 'img-responsvie')) ?>
- </div>
- <div class="odc-acries-desc">
- <h4><?php the_title(); ?></h4>
- <span class="price"><?php echo $product->get_price_html() ?></span>
- </div>
- </a>
- </div>
- </div>
- <?php }
- if( $tax_type == 'Event' ){
- $event_date = get_post_meta(get_the_ID(), 'odc_event_date', true );
- $event_date = strtotime($event_date);
- $today = date('Y-m-d');
- $today = strtotime($today);
- if ($event_date > $today) { ?>
- <div class="col-lg-3 col-sm-4 col-xs-12 grid-item <?php echo $hide_grid; ?>">
- <div class="remaining-posts <?php echo $hide_remaining; ?>">
- <a href="<?php echo $base.'/?s='.$s.'&taxonomy%5B%5D=Event' ?>">
- <?php
- $total_posts = $tquery->found_posts;
- $remaining = $total_posts - 3;
- ?>
- <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
- </a>
- </div>
- <div class="odc-acries-item">
- <a href="<?php echo get_the_permalink(); ?>">
- <div class="odc_acries_image subaccessories">
- <?php if ( has_post_thumbnail() ){
- the_post_thumbnail('odc_featured_product', array('class' => 'img-responsvie'));
- } ?>
- </div>
- <div class="odc-acries-desc">
- <h4><?php the_title(); ?></h4>
- <span class="price"><?php echo $product->get_price_html() ?></span>
- <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>
- <p class="event-day"><?php echo date_i18n('l', strtotime(get_field('odc_event_date', $post->ID, false))); ?></p>
- </div>
- </a>
- </div>
- </div>
- <?php } }
- }
- echo "</div></div>";
- }
- wp_reset_query();
- }
- foreach ( $post_types as $post_type ) {
- $s = isset( $_GET["s"] ) ? $_GET["s"] : "";
- // accepts any wp_query args.
- $args = (array(
- 's' => $s,
- 'post_type' => $post_type,
- 'post_status' => 'publish',
- 'posts_per_page' => -1
- ));
- $query = new WP_Query( $args );
- if ( $query->have_posts() ) {
- if ($post_type == 'outdoorchefrecipe') {
- $row_class="all-recipe";
- $header = __('Recipes', 'outdoorchef');
- }elseif ($post_type == 'page') {
- $row_class="all-recipe";
- $header = __('Others', 'outdoorchef');
- }
- echo '<div class="post-type '. $post_type .'"><div class="post-type-heading">'. $header . '</div><div class="row '.$row_class.'">';
- while( $query->have_posts() ){
- $query->the_post();
- if( $post_type == 'outdoorchefrecipe' ){ ?>
- <div class="col-xs-12 col-sm-6 col-md-3 grid-item all <?php echo $hide_grid; ?>">
- <div class="remaining-posts <?php echo $hide_remaining; ?>">
- <a href="<?php echo $base.'/?s='.$s.'&post_type%5B%5D=outdoorchefrecipe' ?>">
- <?php
- $total_posts = $query->found_posts;
- $remaining = $total_posts - 3;
- ?>
- <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
- </a>
- </div>
- <a href="<?php the_permalink(); ?>">
- <div class="recipe-item">
- <div class="recipe-item-wrap">
- <?php if( has_post_thumbnail() ) the_post_thumbnail(array(262, 208), ['class' => 'img-responsive']); ?>
- <div class="overlay">
- <div class="recipe-item-inner">
- <span class="preview" href=""><?php _e('View Details', 'outdoorchef'); ?></span>
- </div>
- </div>
- </div>
- <div class="recipe-item-info text-center">
- <h3 class="recipe-filter-title"><?php the_title(); ?></h3>
- </div>
- </div>
- </a>
- <!-- <div class="recipe-space"></div> -->
- </div>
- <?php }
- if( $post_type == 'page' ){ ?>
- <div class="col-md-6 pages-search grid-item <?php echo $hide_grid; ?>">
- <div class="remaining-posts <?php echo $hide_remaining; ?>">
- <a href="<?php echo $base.'/?s='.$s.'&post_type%5B%5D=page' ?>">
- <?php
- $total_posts = $query->found_posts;
- $remaining = $total_posts - 3;
- ?>
- <h2 class="remaining"><?php echo "+".$remaining; ?></h2>
- </a>
- </div>
- <a href="<?php the_permalink(); ?>">
- <div class="tile_box">
- <h4 class="tile_content_title"><?php the_title(); ?></h4>
- <p class="tile_content_url"><?php the_permalink(); ?></p>
- <p class="tile_content_desc"><?php the_excerpt(); ?></p>
- </div>
- </a>
- </div>
- <?php }
- }
- echo '</div></div>';
- }
- }
- if ( (!$tquery->have_posts()) && (!$query->have_posts()) ) { ?>
- <h2 class="no-result-found"><?php echo __("We could not find a match for ", "outdoorchef-search").'\''.$s.'\''.__(' ', 'outdoorchef-search') ?></h2>
- <h2 class="no-result-found"><?php echo __('Please try another term', 'outdoorchef-search') ?></h2>
- <?php }
- echo '</div><br>'; // .search-content
- ?>
- </main><!-- #main -->
- </div><!-- #primary -->
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement