0
votes

I have implemented Wordpress search : posts_search filter.

add_filter( 'posts_search', 'extend_search', 500, 2 );

function extend_search($search, &$wp_query) {
        error_log(json_encode($wp_query)); 
        $terms = $wp_query->query_vars[ 's' ];
        error_log(json_encode($terms));
        .
        .
        .
        return $search
}

Issue : When I search a very long text, I am redirected to homepage.

i.e. For example

I searched :
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.

Result homepage URL : https://my.test.com/~user/test/?s=Lorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+elit.+Aenean+commodo+ligula+eget+dolor.+Aenean+massa.+Cum+sociis+natoque+penatibus+et+magnis+dis+parturient+montes%2C+nascetur+ridiculus+mus.+Donec+quam+felis%2C+ultricies+nec%2C+pellentesque+eu%2C+pretium+quis%2C+sem.+Nulla+consequat+massa+quis+enim.+Donec+pede+justo%2C+fringilla+vel%2C+aliquet+nec%2C+vulputate+eget%2C+arcu.+In+enim+justo%2C+rhoncus+ut%2C+imperdiet+a%2C+venenatis+vitae%2C+justo.+Nullam+dictum+felis+eu+pede+mollis+pretium.+Integer+tincidunt.+Cras+dapibus.+Vivamus+elementum+semper+nisi.+Aenean+vulputate+eleifend+tellus.+Aenean+leo+ligula%2C+porttitor+eu%2C+consequat+vitae%2C+eleifend+ac%2C+enim.+Aliquam+lorem+ante%2C+dapibus+in%2C+viverra+quis%2C+feugiat+a%2C+tellus.+Phasellus+viverra+nulla+ut+metus+varius+laoreet.+Quisque+rutrum.+Aenean+imperdiet.+Etiam+ultricies+nisi+vel+augue.+Curabitur+ullamcorper+ultricies+nisi.+Nam+eget+dui.

And logged values :

wp_query : {"query":[],"query_vars":{"error":"","m":"","p":0,"post_parent":"","subpost":"","subpost_id":"","attachment":"","attachment_id":0,"name":"","static":"","pagename":"","page_id":0,"second":"","minute":"","hour":"","day":0,"monthnum":0,"year":0,"w":0,"category_name":"","tag":"","cat":11,"tag_id":"","author":"","author_name":"","feed":"","tb":"","paged":0,"comments_popup":"","meta_key":"","meta_value":"","preview":"","s":"","sentence":"","title":"","fields":"","menu_order":"","category__in":[],"category__not_in":[],"category__and":[],"post__in":[],"post__not_in":[],"post_name__in":[],"tag__in":[],"tag__not_in":[],"tag__and":[],"tag_slug__in":[],"tag_slug__and":[],"post_parent__in":[],"post_parent__not_in":[],"author__in":[],"author__not_in":[],"ignore_sticky_posts":false,"suppress_filters":false,"cache_results":true,"update_post_term_cache":true,"update_post_meta_cache":true,"post_type":"","posts_per_page":2,"nopaging":false,"comments_per_page":"50","no_found_rows":false},"tax_query":{"queries":[],"relation":"AND","queried_terms":[],"primary_table":null,"primary_id_column":null},"meta_query":{"queries":[],"relation":null,"meta_table":null,"meta_id_column":null,"primary_table":null,"primary_id_column":null},"date_query":false,"post_count":0,"current_post":-1,"in_the_loop":false,"comment_count":0,"current_comment":-1,"found_posts":0,"max_num_pages":0,"max_num_comment_pages":0,"is_single":false,"is_preview":false,"is_page":false,"is_archive":false,"is_date":false,"is_year":false,"is_month":false,"is_day":false,"is_time":false,"is_author":false,"is_category":false,"is_tag":false,"is_tax":false,"is_search":false,"is_feed":false,"is_comment_feed":false,"is_trackback":false,"is_home":true,"is_404":false,"is_embed":false,"is_comments_popup":false,"is_paged":false,"is_admin":false,"is_attachment":false,"is_singular":false,"is_robots":false,"is_posts_page":false,"is_post_type_archive":false,"thumbnails_cached":false,"updated_term_meta_cache":false,"updated_comment_meta_cache":false}

terms : ""

search query : ( ((wp_posts.post_title) LIKE '%%') OR ((wp_posts.post_content) LIKE '%%') )

So, For long search string, query variable is empty and I am being redirected to homepage with query variable :

 is_home = true
 is_search = false

Can someone please help to resolve this. Thanks

1

1 Answers

0
votes

Found the solution... please refer to solution on : Max size of URL parameters in _GET

I checked the php configuration using :

<?php
  phpinfo();
?>

And found suhosin extension variable for GET parameters set to 512 characters:

suhosin.get.max_value_length    512