Support » Plugin: Relevanssi - A Better Search » [Plugin: Relevanssi – A Better Search] Using posts_search filter in RelevanSSI (or equivalent)

  • 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/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mikko Saari

    (@msaari)

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

    Plugin Author Mikko Saari

    (@msaari)

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

    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!

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

    Plugin Author Mikko Saari

    (@msaari)

    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.

    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Using posts_search filter in RelevanSSI (or equivalent)’ is closed to new replies.