Digital experiences for all disciplines
New Landing › How can we help? › Atelier › Search just pages on Fullscreen Search
New Landing › How can we help? › Atelier › Search just pages on Fullscreen Search
- This topic has 5 replies, 3 voices, and was last updated 8 years by David Martin – Support.
-
Posted in: Atelier
-
June 26, 2016 at 1:53 am #277176
Hello again!
There any way that search results pages, portfolios and blog just appear? No galleries, customers, testimonials, etc … just pages, portfolio and blog entries are displayed.
I tried to use this plugin https://wordpress.org/plugins/osd-exclude-from-search-results/ and it works in the results page, but not works with the results on Fullscreen Search results. Notice in the screenshot attached for example.
Thanks for the support!
Attachments:
You must be logged in to view attached files.June 28, 2016 at 9:52 am #277638HI,
Please install and activate your child theme, within the
functions.php
please add this:/* * AJAX SEARCH OVERRIDE * ------------------------------------------------ * @original - /swift-framework/core/sf-header.php * ================================================== */ if (!function_exists('sf_ajaxsearch')) { 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' => array( 'post', 'portfolio' ), '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_type = get_post_type($post); $product = array(); if ( $post_type == "product" ) { $product = new WC_Product( $post->ID ); if (!$product->is_visible()) { return; } } $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 .= '<a href="'.$post_permalink.'" class="search-result-link"></a>'; $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 ($post_type == "product") { $search_results_ouput .= $product->get_price_html(); } 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) { $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; } if ($header_search_type == "fs-search-on") { $search_results_ouput .= '<a href="'.$search_link.'" class="all-results">'.sprintf(__("View all %d results", "swiftframework"), $count).'</a>'; } else { $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(); } add_action('wp_ajax_sf_ajaxsearch', 'sf_ajaxsearch'); add_action('wp_ajax_nopriv_sf_ajaxsearch', 'sf_ajaxsearch'); }
June 28, 2016 at 11:04 pm #277904It works for me! Thanks you so much!!
Another question, please, How I can change the text in the name of the category in search results? For example, change it for “news” or something like this. See in the attachment.
Thanks again!!
Attachments:
You must be logged in to view attached files.June 29, 2016 at 5:53 pm #278189That’s the name of the custom post type defined in WordPress not sure if it’s possible to change it but you can try to translate it to something else using this plugin.
replace post by news
This will affect the entire site.
-Rui
June 29, 2016 at 6:35 pm #278198Ok! Thanks for the support! 😉
June 29, 2016 at 6:49 pm #278205Thanks Rui, glad this helped you out.
– David.
-
Posted in: Atelier
You must be logged in and have valid license to reply to this topic.