WordPress.org

Support

Support » Plugins and Hacks » SearchAutocomplete » [Resolved] [Plugin: SearchAutocomplete] [PATCH] Support custom post types

[Resolved] [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/

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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");

    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");

    To add 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

    @hereswhatidid

    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

    Plugin Author Gabe Shackle

    @hereswhatidid

    Closing this due to inactivity.

    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 ‘[Resolved] [Plugin: SearchAutocomplete] [PATCH] Support custom post types’ is closed to new replies.
Skip to toolbar