New Landing How can we help? Themeforest Theme Support Dante Exclude post: types OR ID's from Ajax search

Viewing 2 posts - 1 through 2 (of 2 total)
  • Posted in: Dante
  • #90602
    dekkydog
    Member
    Post count: 59

    Hi there,
    I have a number of plugins running alongside the dante theme. Some of these plugins have there own unique custom post types / ID’s. When using the Dante Ajax search ALL plugin custom post types are included in the dynamic dropdown results. Is there a way to exclude certain custom post types or ID’s from the dropdown? Note that I am using the Child-theme – It would be nice to slip in something to my functions.php which solved this?

    Thanks in advance for your time 🙂

    Cheers

    #91094
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please insert given below code at functions.php and you can modified this as you want.

    function sf_ajaxsearch() {
    			$search_term = trim($_POST['s']);
    			$search_query_args = array(
    				's' => $search_term,
    				'post_type' => 'any',
    				'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;
    
    			$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->ID);
    			        	
    			        	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">';
    			        	
    			        	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") {
    			            $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) {
    			    	$search_results_ouput .= '<a href="'.get_search_link($search_term).'" 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();
    		}

    Hope that should help to you.

    Thanks

Viewing 2 posts - 1 through 2 (of 2 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