WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
[resolved] Using posts_search filter in RelevanSSI (or equivalent) (7 posts)

  1. Zach Schnackel
    Member
    Posted 1 year ago #

    Hi Mikko,
    Awesome plugin! I have run into a bit of a snag - you mention that RelevanSSI replaces the default WordPress Search, does it also override the posts_search filter? I wrote http://pastebin.com/XnvbfpfS which basically takes the search term, finds if it has 'TL' in the term and then returns (in addition) 'TL-' as a search term pre/appended onto whatever else is attached to it). After enabling RelevanSSI, the filter does not work anymore. Is relevanssi_do_query() what I'm looking for here? Do you have a quick example of how I could plug into this area? Thanks!

    This is being used to search for post titles --> as most people type in TL123 instead of TL-123 (the filter I wrote attempts to fix that)

    I tried to use the "synonym" area, but I believe it's looking for whole terms and not "parts of terms". Is there any regex available in that area as well?

    http://wordpress.org/extend/plugins/relevanssi/

  2. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Use the Relevanssi filter hook relevanssi_mofidy_wp_query to change search query ($wp_query->query_vars['s']) before Relevanssi sees it.

  3. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    If you add the variant form to the search query, make sure you're using OR operator.

  4. Zach Schnackel
    Member
    Posted 1 year ago #

    Hi Mikko,
    Thanks for the response. Here's what I have so far: http://pastebin.com/baA6KxFb

    But after I have the "new_search" variable, I'm not sure how to plug it into wp_query and also change the operator to OR. Would you be able to help me hook that part up? I'd really appreciate it - will be buying the developer version once I know this part works as needed. Thanks!

  5. Zach Schnackel
    Member
    Posted 1 year ago #

    Hi Mikko,
    Emailed through regular support (with developer version license). Thanks.

  6. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Once you have the search string with the added parts, just store it in $wp_query->query_vars['s'] and return the updated $wp_query. That's all there is - you don't have to worry about queries or MySQL code.

    So, if $wp_query->query_vars['s'] is "TL123", you need to modify it to "TL123 TL-123" and then store that in $wp_query->query_vars['s']. Nothing else.

    The default operator is set on the Relevanssi settings page, look there.

  7. Zach Schnackel
    Member
    Posted 1 year ago #

    Very cool! Here's the final result: http://pastebin.com/huke6FNe

    For everyone else (which I'll be doing as well), just pass in that $replace_var via something more dynamic (like a plugin option) so you can change that from site to site.

    Thanks again Mikko!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic