Replace a single variable with add_filter

7 months ago 39

I'm trying to hook to a relation successful class-wp-query.php and regenerate a azygous adaptable – $searchand = ' AND ' into $searchand = ' OR '. The trouble, I assume, is that it's lone the 3rd occurence of the variable.

My usage lawsuit is to telephone a fallback hunt query for erstwhile determination are excessively fewer oregon nary hunt results, expecting that each word mightiness bring up something.

First I tried simply mounting the caller variable...

function or_search( $searchand ) { $searchand = ' OR '; } add_filter( 'posts_search', 'or_search', 500, 2 );

...but seemingly it changes thing other (different query results, but not the ones one spot erstwhile I edit the halfway directly).

Also tried to lucifer it somehow...

function or_search( $searchand ) { $searchand = get_defined_vars($searchand); $searchand = str_replace('+', '"', http_build_query($searchand, null, ',')); $searchand = str_replace('AND','OR',$searchand); instrumentality $searchand; } add_filter( 'posts_search', 'or_search', 500, 2 );

...but though it seems to enactment successful sandbox, erstwhile I hook it it breaks the leafage altogether, truthful surely I'm doing thing wrong.

Read Entire Article

Our Ventures