Support » Plugin: Relevanssi - A Better Search » Custom Parameter in User Searches

  • Resolved Waren Gonzaga

    (@warengonzaga)


    I have a website that I made a custom search on it… I want to only show products instead of post and anything I just want a products data and meta only. I achieve that but the only issue is the user searches in the backend…

    When a user search in the website it fires up “/?s=KEYWORD&post_type=product”
    That’s fine and cool however when I go to the backend of the site and go to user searches which is the logs of end users who search in the website…. and click some of the keywords there it fires up this “/?s=KEYWORD” only.

    I want to achieve that when I click any keyword in the user searches it must fires “/?s=KEYWORD&post_type=product” to make it consistent. How I can achieve that?

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

    (@msaari)

    That’s unfortunately not possible. Relevanssi doesn’t log the search parameters, only the search terms, and thus the user searches list never includes any parameters. The user searches page will always show the searches without any parameters at all, and right now there’s no way to change that without modifying the plugin code so that the searches include the post type parameter.

    Thread Starter Waren Gonzaga

    (@warengonzaga)

    Hello @msaari yeah I think of modifying the code… how I can do that? can you guide me which part I can modify it?

    Plugin Author Mikko Saari

    (@msaari)

    In lib/interface.php, you need to change this line:

    $query_url = $url . '/?s=' . $search_parameter;

    to include the post type parameter, ie. add &post_type=product to the $query_url variable. You also need to be prepared to make this change again every time you update Relevanssi.

    Thread Starter Waren Gonzaga

    (@warengonzaga)

    Hi @msaari I may request this feature for your future users? Also, thanks for helping! I will do it… this is to achieve what I need to achieve!

    Plugin Author Mikko Saari

    (@msaari)

    Yeah, actually. Replace the line with this:

    $query_url = apply_filters( 'relevanssi_user_searches_query_url', $url . '/?s=' . $search_parameter );

    Then you can use the relevanssi_user_searches_query_url filter hook to change the URLs from theme functions.php, and that will be update-proof – I’ll add that filter in the next version.

    Plugin Author Mikko Saari

    (@msaari)

    So you can do

    add_filter( 'relevanssi_user_searches_query_url', function( $url ) { return $url . '&post_type=product'; } );

    Thread Starter Waren Gonzaga

    (@warengonzaga)

    I like it @msaari ! That’s what I’m looking for! That would be less headache and lessen the update task.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Parameter in User Searches’ is closed to new replies.