New Landing How can we help? Atelier Search just pages on Fullscreen Search

Viewing 6 posts - 1 through 6 (of 6 total)
  • Posted in: Atelier
  • #277176
    quinope
    Member
    Post count: 19

    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.
    #277638
    David Martin – Support
    Moderator
    Post count: 20834

    HI,

    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');
    	}
    #277904
    quinope
    Member
    Post count: 19

    It 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.
    #278189
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    That’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.

    Real-Time Find and Replace

    replace post by news

    This will affect the entire site.

    -Rui

    #278198
    quinope
    Member
    Post count: 19

    Ok! Thanks for the support! 😉

    #278205
    David Martin – Support
    Moderator
    Post count: 20834

    Thanks Rui, glad this helped you out.

    – David.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register