• Resolved engray95

    (@engray95)


    Hi, I’m using Relevanssi as my main search engine and it’s awesome!
    Sadly, it looks like it also breaks my other “search” (more like post filter).
    I’m using get_posts to display post from particular post type (real example at the end of this post). To filter post by name I’m using ‘s’ param from wp_query/parse_query.

    Here is how I use it:

    $search_term = $_GET['filter']; // get filter param from URL, it is working fine, I've checked
    $postsArgsArray = [];
    if(isset($_GET['filter'])) {
                $postsArgsArray = [
                    'posts_per_page'	=> -1,
                    'post_type'			=> 'shops',
                    's' => $search_term,
                    'orderby' => 'title',
                    'order'   => 'ASC',
                ];
            }
    
    $shops = get_posts($shopsArgsArray);
    foreach($shops as $p) {
      setup_postdata($p); 
      echo $p->post_title;
    }

    After disabling Relevanssi this code works perfectly fine, it also used to work few months back. I’d much appreciate your help / any suggestions on how I could fix this 🙂

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

    (@msaari)

    That’s a search, and Relevanssi takes over searches. If you want to disable Relevanssi, just unhook it:

    remove_filter('posts_request', 'relevanssi_prevent_default_request'); 
    remove_filter('the_posts', 'relevanssi_query', 99);

    The first one in particular is the one that stops your search working.

    Thread Starter engray95

    (@engray95)

    Hi @msaari thanks for quick and meaningful response, I used your code and it worked, thanks!
    What came as surprise to me it’s that main page search still works quite the same as before adding those 2 lines. Results seem to be the same, but order of search results is different, which is fine. If I may know, what exactly happens after applying above code? It’s not the same as disabling Relevanssi plugin, am I correct?

    Plugin Author Mikko Saari

    (@msaari)

    Well, it depends where you add those lines – those two lines do completely disable Relevanssi, but only where you add them. So, if you add them right next to your get_posts() query, they’ll only disable Relevanssi there and then, but if you add those lines to every page load, Relevanssi will be completely disabled.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Relevanssi breaks get_posts ‘s’ param’ is closed to new replies.