KnowledgePress WordPress Theme LiveSearch Fix

Many of you are experiencing BROKEN search results in this theme.

The Symptom

‘Page Not Found’.

The Trigger

When you add an anchor tag or any open tag to the first 100 characters of the post and don’t close the tag before the 100 characters run out.

The Cause

Bad development.

The Author’s “Fix”

Don’t put anything neat-o in the first 100 characters of your posts.

The Real Fix

  1. Open wp-content/themes/knowledgepress/lib/custom.php
  2. Delete lines 133 – 148. They should read:
    		if (gt_get_option('live_search_in') == '2') {
    			$sql_query = $wpdb->prepare( "SELECT ID, post_title, SUBSTRING(post_content,1,100) as post_content, post_name from $wpdb->posts where post_status = %s and post_type in ( $post_type )and (post_title like %s or post_content like %s)", $post_status, $search_term, $search_term );
    	    } else {
    			$sql_query = $wpdb->prepare( "SELECT ID, post_title, SUBSTRING(post_content,1,100) as post_content, post_name from $wpdb->posts where post_status = %s and post_type in ( $post_type )and post_title like %s", $post_status, $search_term );
    	    }
    
    		$results = $wpdb->get_results($sql_query);
    
    		$search_json = array( "query" => "Unit", "suggestions" => array() );   // create a json array
    
    		foreach ( $results as $result ) {
    			$link	=	get_permalink( $result->ID ); // get post url
    
    			$search_json["suggestions"][] = array(
    													"value" => $result->post_title,
    													"data"  => array( "content" => $result->post_content, "url" => $link )
  3. Replace it with this:
    		if (gt_get_option('live_search_in') == '2') {
    			$sql_query = $wpdb->prepare( "SELECT ID, post_title, post_content, post_name from $wpdb->posts where post_status = %s and post_type in ( $post_type )and (post_title like %s or post_content like %s)", $post_status, $search_term, $search_term );
    	    } else {
    			$sql_query = $wpdb->prepare( "SELECT ID, post_title, post_content, post_name from $wpdb->posts where post_status = %s and post_type in ( $post_type )and post_title like %s", $post_status, $search_term );
    	    }
    
    		$results = $wpdb->get_results($sql_query);
    
    		$search_json = array( "query" => "Unit", "suggestions" => array() );   // create a json array
    
    		foreach ( $results as $result ) {
    			$link	=	get_permalink( $result->ID ); // get post url
    
    			$search_json["suggestions"][] = array(
    													"value" => $result->post_title,
    													"data"  => array( "content" => substr(strip_tags($result->post_content), 0, 100), "url" => $link )