function sf_ajaxsearch()
 {
     global $sf_options;
     $page_classes = sf_page_classes();
     $header_layout = $page_classes['header-layout'];
     $header_search_type = $sf_options['header_search_type'];
     $header_search_pt = $sf_options['header_search_pt'];
     $search_term = trim($_POST['s']);
     $search_query_args = array('s' => $search_term, 'post_type' => $header_search_pt, 'post_status' => 'publish', 'suppress_filters' => false, 'numberposts' => -1);
     $search_query_args = http_build_query($search_query_args);
     $search_results = get_posts($search_query_args);
     $count = count($search_results);
     $shown_results = 5;
     if ($header_layout == "header-vert" || $header_layout == "header-vert-right") {
         $shown_results = 2;
     }
     if ($header_search_type == "fs-search-on") {
         $shown_results = 20;
     }
     $search_results_ouput = "";
     if (!empty($search_results)) {
         $sorted_posts = $post_type = array();
         foreach ($search_results as $search_result) {
             $sorted_posts[$search_result->post_type][] = $search_result;
             // Check we don't already have this post type in the post_type array
             if (empty($post_type[$search_result->post_type])) {
                 // Add the post type object to the post_type array
                 $post_type[$search_result->post_type] = get_post_type_object($search_result->post_type);
             }
         }
         $i = 0;
         foreach ($sorted_posts as $key => $type) {
             $search_results_ouput .= '<div class="search-result-pt">';
             if ($header_search_type == "fs-search-on") {
                 if (isset($post_type[$key]->labels->name)) {
                     $search_results_ouput .= "<h3>" . $post_type[$key]->labels->name . "</h3>";
                 } else {
                     if (isset($key)) {
                         $search_results_ouput .= "<h3>" . $key . "</h3>";
                     } else {
                         $search_results_ouput .= "<h3>" . __("Other", "swiftframework") . "</h3>";
                     }
                 }
             }
             foreach ($type as $post) {
                 $post_title = get_the_title($post->ID);
                 $post_date = get_the_time(get_option('date_format'), $post->ID);
                 $post_permalink = get_permalink($post->ID);
                 $image = get_the_post_thumbnail($post->ID, 'thumb-square');
                 if ($image) {
                     $search_results_ouput .= '<div class="search-result has-img">';
                     $search_results_ouput .= '<div class="search-item-img"><a href="' . $post_permalink . '">' . $image . '</div>';
                 } else {
                     $search_results_ouput .= '<div class="search-result">';
                 }
                 $search_results_ouput .= '<div class="search-item-content">';
                 if ($header_search_type == "fs-search-on") {
                     $search_results_ouput .= '<h4><a href="' . $post_permalink . '">' . $post_title . '</a></h4>';
                 } else {
                     $search_results_ouput .= '<h5><a href="' . $post_permalink . '">' . $post_title . '</a></h5>';
                 }
                 if (get_post_type($post) == "product") {
                     $price = sf_get_post_meta($post->ID, '_regular_price', true);
                     $sale = sf_get_post_meta($post->ID, '_sale_price', true);
                     if ($sale != "") {
                         $price = $sale;
                     }
                     if ($price != "") {
                         $search_results_ouput .= '<span>' . get_woocommerce_currency_symbol() . $price . '</span>';
                     }
                 } else {
                     $search_results_ouput .= '<time>' . $post_date . '</time>';
                 }
                 $search_results_ouput .= '</div>';
                 $search_results_ouput .= '</div>';
                 $i++;
                 if ($i == $shown_results) {
                     break;
                 }
             }
             $search_results_ouput .= '</div>';
             if ($i == $shown_results) {
                 break;
             }
         }
         if ($count > 1) {
             if ($header_search_type == "fs-search-on") {
                 $search_link = get_home_url() . '?s=' . $search_term . '&post_type=' . $header_search_pt;
                 $search_results_ouput .= '<a href="' . $search_link . '" class="all-results">' . sprintf(__("View all %d results", "swiftframework"), $count) . '</a>';
             } else {
                 $search_link = get_home_url() . '?s=' . $search_term . '&post_type=' . $header_search_pt;
                 $search_results_ouput .= '<a href="' . $search_link . '" class="all-results sf-button black bordered">' . sprintf(__("View all %d results", "swiftframework"), $count) . '</a>';
             }
         }
     } else {
         $search_results_ouput .= '<div class="no-search-results">';
         $search_results_ouput .= '<h5>' . __("No results", "swiftframework") . '</h5>';
         $search_results_ouput .= '<p>' . __("No search results could be found, please try another query.", "swiftframework") . '</p>';
         $search_results_ouput .= '</div>';
     }
     echo $search_results_ouput;
     die;
 }
Example #2
0
<!--// OPEN HTML //-->
<html <?php 
language_attributes();
?>
>

	<!--// OPEN HEAD //-->
	<head>
		
		<!-- Manually set render engine for Internet Explorer, prevent any plugin overrides -->
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10">
		
		<?php 
$page_class = "";
if (function_exists('sf_page_classes')) {
    $page_classes = sf_page_classes();
    $page_class = $page_classes['page'];
}
global $post, $sf_options;
$extra_page_class = $page_header_type = "";
$page_layout = $sf_options['page_layout'];
$header_layout = $sf_options['header_layout'];
if (isset($_GET['layout'])) {
    $page_layout = $_GET['layout'];
}
if ($post) {
    $extra_page_class = sf_get_post_meta($post->ID, 'sf_extra_page_class', true);
}
if (is_page() && $post) {
    $page_header_type = sf_get_post_meta($post->ID, 'sf_page_header_type', true);
}
Example #3
0
 function sf_ajaxsearch()
 {
     global $sf_options;
     $page_classes = sf_page_classes();
     $header_layout = $page_classes['header-layout'];
     $header_search_type = $sf_options['header_search_type'];
     $header_search_pt = $sf_options['header_search_pt'];
     $remove_dates = $sf_options['remove_dates'];
     $search_term = trim($_POST['s']);
     $search_query_args = array('s' => $search_term, 'post_type' => $header_search_pt, 'post_status' => 'publish', 'suppress_filters' => false, 'numberposts' => -1);
     $search_query_args = http_build_query($search_query_args);
     $search_results = get_posts($search_query_args);
     $count = count($search_results);
     $shown_results = 5;
     if ($header_layout == "header-vert" || $header_layout == "header-vert-right") {
         $shown_results = 2;
     }
     if ($header_search_type == "fs-search-on") {
         $shown_results = 20;
     }
     $search_results_ouput = "";
     if (!empty($search_results)) {
         $sorted_posts = $post_type = array();
         foreach ($search_results as $search_result) {
             $sorted_posts[$search_result->post_type][] = $search_result;
             // Check we don't already have this post type in the post_type array
             if (empty($post_type[$search_result->post_type])) {
                 // Add the post type object to the post_type array
                 $post_type[$search_result->post_type] = get_post_type_object($search_result->post_type);
             }
         }
         $i = 0;
         foreach ($sorted_posts as $key => $type) {
             $search_results_ouput .= '<div class="search-result-pt">';
             if (isset($post_type[$key]->labels->name)) {
                 $search_results_ouput .= "<h6>" . $post_type[$key]->labels->name . "</h6>";
             } else {
                 if (isset($key)) {
                     $search_results_ouput .= "<h6>" . $key . "</h6>";
                 } else {
                     $search_results_ouput .= "<h6>" . __("Other", "swiftframework") . "</h6>";
                 }
             }
             foreach ($type as $post) {
                 $img_icon = "";
                 $post_format = get_post_format($post->ID);
                 if ($post_format == "") {
                     $post_format = 'standard';
                 }
                 $post_type = get_post_type($post);
                 $product = array();
                 if ($post_type == "product") {
                     $product = new WC_Product($post->ID);
                     if (!$product->is_visible()) {
                         return;
                     }
                 }
                 if ($post_type == "post") {
                     if ($post_format == "quote" || $post_format == "status") {
                         $img_icon = "ss-quote";
                     } else {
                         if ($post_format == "image") {
                             $img_icon = "ss-picture";
                         } else {
                             if ($post_format == "chat") {
                                 $img_icon = "ss-chat";
                             } else {
                                 if ($post_format == "audio") {
                                     $img_icon = "ss-music";
                                 } else {
                                     if ($post_format == "video") {
                                         $img_icon = "ss-video";
                                     } else {
                                         if ($post_format == "link") {
                                             $img_icon = "ss-link";
                                         } else {
                                             $img_icon = "ss-pen";
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     if ($post_type == "product") {
                         $img_icon = "ss-cart";
                     } else {
                         if ($post_type == "portfolio") {
                             $img_icon = "ss-picture";
                         } else {
                             if ($post_type == "team") {
                                 $img_icon = "ss-user";
                             } else {
                                 if ($post_type == "galleries") {
                                     $img_icon = "ss-picture";
                                 } else {
                                     $img_icon = "ss-file";
                                 }
                             }
                         }
                     }
                 }
                 $post_title = get_the_title($post->ID);
                 $post_date = get_the_date();
                 $post_permalink = get_permalink($post->ID);
                 $image = get_the_post_thumbnail($post->ID, 'thumbnail');
                 $search_results_ouput .= '<div class="search-result">';
                 $search_results_ouput .= '<a href="' . $post_permalink . '" class="search-result-link"></a>';
                 if ($image) {
                     $search_results_ouput .= '<div class="search-item-img"><a href="' . $post_permalink . '">' . $image . '</div>';
                 } else {
                     $search_results_ouput .= '<div class="search-item-img"><a href="' . $post_permalink . '" class="img-holder"><i class="' . $img_icon . '"></i></a></div>';
                 }
                 $search_results_ouput .= '<div class="search-item-content">';
                 $search_results_ouput .= '<h5><a href="' . $post_permalink . '">' . $post_title . '</a></h5>';
                 if ($post_type == "product") {
                     $search_results_ouput .= $product->get_price_html();
                 } else {
                     if (!$remove_dates) {
                         $search_results_ouput .= '<time>' . $post_date . '</time>';
                     }
                 }
                 $search_results_ouput .= '</div>';
                 $search_results_ouput .= '</div>';
                 $i++;
                 if ($i == $shown_results) {
                     break;
                 }
             }
             $search_results_ouput .= '</div>';
             if ($i == $shown_results) {
                 break;
             }
         }
         if ($count > 1) {
             $search_link = get_search_link($search_term);
             if (strpos($search_link, '?') !== false) {
                 $search_link .= '&post_type=' . $header_search_pt;
             } else {
                 $search_link .= '?post_type=' . $header_search_pt;
             }
             $search_results_ouput .= '<a href="' . $search_link . '" class="all-results">' . sprintf(__("View all %d results", "swiftframework"), $count) . '</a>';
         }
     } else {
         $search_results_ouput .= '<div class="no-search-results">';
         $search_results_ouput .= '<h6>' . __("No results", "swiftframework") . '</h6>';
         $search_results_ouput .= '<p>' . __("No search results could be found, please try another query.", "swiftframework") . '</p>';
         $search_results_ouput .= '</div>';
     }
     echo $search_results_ouput;
     die;
 }