Title: [Plugin: SearchAutocomplete] [PATCH] Support custom post types
Last modified: August 20, 2016

---

# [Plugin: SearchAutocomplete] [PATCH] Support custom post types

 *  Resolved [Daedalon](https://wordpress.org/support/users/daedalon/)
 * (@daedalon)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-searchautocomplete-patch-support-custom-post-types/)
 * To add support for custom post types, open includes/tags.php and change line 
   70 from
 * `$titles = $wpdb->get_results("SELECT post_title As name, ID as post_id, guid
   AS url, 1 cnt FROM ".$wpdb->prefix."posts t WHERE post_status='publish' and (
   post_type='post' OR post_type='page') and post_date < NOW() and post_title LIKE'%".
   mysql_real_escape_string($term)."%' ORDER BY post_title");`
 * to
 * `$titles = $wpdb->get_results("SELECT post_title As name, ID as post_id, guid
   AS url, 1 cnt FROM ".$wpdb->prefix."posts t WHERE post_status='publish' and post_date
   < NOW() and post_title LIKE '%".mysql_real_escape_string($term)."%' ORDER BY 
   post_title");`
 * In other words, just remove the check for post_type.
 * [http://wordpress.org/extend/plugins/search-autocomplete/](http://wordpress.org/extend/plugins/search-autocomplete/)

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

 *  Thread Starter [Daedalon](https://wordpress.org/support/users/daedalon/)
 * (@daedalon)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-searchautocomplete-patch-support-custom-post-types/#post-2938968)
 * To limit the amount of results returned, add `LIMIT 10` before the last closing`"`,
   where 10 is the maximum amount of results you want to display. The resulting 
   line 70 will then look like this:
 * `$titles = $wpdb->get_results("SELECT post_title As name, ID as post_id, guid
   AS url, 1 cnt FROM ".$wpdb->prefix."posts t WHERE post_status='publish' and post_date
   < NOW() and post_title LIKE '%".mysql_real_escape_string($term)."%' ORDER BY 
   post_title LIMIT 7");`
 *  Thread Starter [Daedalon](https://wordpress.org/support/users/daedalon/)
 * (@daedalon)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-searchautocomplete-patch-support-custom-post-types/#post-2939068)
 * To roughly display posts of certain type before others, add `post_type ASC,` 
   or `post_type DESC,` in between `ORDER BY` and `post_title` in the end. This 
   displays the results grouped in alphabetical or reverse alphabetical order of
   the post type. To display eg. events before locations or pages before posts, 
   use the first option (ASC), or to do it the other way around, the second.
 * Here’s an example line 70 with corrections in SQL capitalizations for improved
   readability and an unused query part (guid AS url) removed for performance:
 * `$titles = $wpdb->get_results("SELECT post_title AS name, ID AS post_id, post_type,
   1 cnt FROM ".$wpdb->prefix."posts t WHERE post_status='publish' AND post_date
   < NOW() AND post_title LIKE '%".mysql_real_escape_string($term)."%' ORDER BY 
   post_type DESC,post_title LIMIT 10");`
 *  Thread Starter [Daedalon](https://wordpress.org/support/users/daedalon/)
 * (@daedalon)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-searchautocomplete-patch-support-custom-post-types/#post-2939097)
 * To add [qTranslate](https://wordpress.org/extend/plugins/qtranslate/) support,
   change includes/tags.php line 72 from
 * `$row_array['label'] = $word->name;`
 * to
 * `$row_array['label'] = __($word->name);`
 * Despite displaying the titles in the site’s default language regardless of the
   user’s language setting, this is a considerable improvement over the previously
   shown <!–:en–>Post Name<!–:–><!–:fi–>Artikkelin nimi<!–:–> jumble.
 *  Plugin Author [Gabe Shackle](https://wordpress.org/support/users/hereswhatidid/)
 * (@hereswhatidid)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/plugin-searchautocomplete-patch-support-custom-post-types/#post-2939200)
 * I’ve added some filters to the plugin that should allow to handle all these situations.
   Can you try upgrading to 2.0.2 and let me know if that clears it up?
 * [Filter Documentation](http://hereswhatidid.com/search-autocomplete/)
 *  Plugin Author [Gabe Shackle](https://wordpress.org/support/users/hereswhatidid/)
 * (@hereswhatidid)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/plugin-searchautocomplete-patch-support-custom-post-types/#post-2939201)
 * Closing this due to inactivity.
 *  Thread Starter [Daedalon](https://wordpress.org/support/users/daedalon/)
 * (@daedalon)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/plugin-searchautocomplete-patch-support-custom-post-types/#post-2939202)
 * Tested with 2.0.4 and qTranslate support seems to be fine by default. If further
   needs arise, I’ll look into the filters and get back to this thread if appropriate.
 * Thanks a lot for your great work on the plugin!

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

The topic ‘[Plugin: SearchAutocomplete] [PATCH] Support custom post types’ is closed
to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/search-autocomplete_f8fbfd.svg)
 * [SearchAutocomplete](https://wordpress.org/plugins/search-autocomplete/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/search-autocomplete/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/search-autocomplete/)
 * [Active Topics](https://wordpress.org/support/plugin/search-autocomplete/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/search-autocomplete/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/search-autocomplete/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [Daedalon](https://wordpress.org/support/users/daedalon/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/plugin-searchautocomplete-patch-support-custom-post-types/#post-2939202)
 * Status: resolved