WordPress.org

Ready to get started?Download WordPress

Forums

SearchAutocomplete
[resolved] [PATCH] Support custom post types (7 posts)

  1. Daedalon
    Member
    Posted 1 year ago #

    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/

  2. Daedalon
    Member
    Posted 1 year ago #

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

  3. Daedalon
    Member
    Posted 1 year ago #

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

  4. Daedalon
    Member
    Posted 1 year ago #

    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.

  5. hereswhatidid
    Member
    Plugin Author

    Posted 1 year ago #

    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

  6. hereswhatidid
    Member
    Plugin Author

    Posted 1 year ago #

    Closing this due to inactivity.

  7. Daedalon
    Member
    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.