Force is_search to always TRUE
You can force WordPress to load search.php template when you need it by using the following code: add_filter( ‘template_include’, ‘get_search_template’ ); instead of $q->set( ‘is_search’, true );
You can force WordPress to load search.php template when you need it by using the following code: add_filter( ‘template_include’, ‘get_search_template’ ); instead of $q->set( ‘is_search’, true );
… the call works fine as it actually echos “nope” where it’s supposed to, are you saying that it may be a problem because I’m making an ajax call which is not search.php? An Ajax call is a new request to the server. The page that loads is (should be) wp-admin/admin-ajax.php which is template neutral. … Read more
First of all, one never should rely on raw $_REQUEST: believe me, this is a security issue. PHP has 2 functions: filter_input and filter_input_array that helps you to sanitize your request data. In addition, in your request dump I don’t see any $_REQUEST[‘custom_bath’], but you are using that value, that can be a cause for … Read more
Yes this will be possible. I would suggest integrating your WordPress websites search with Google search and then you can specify the site/s (in your cause Site B) you wish to search when a users performs a search on your current site (Site A) Here is a awesome and simple tutorial a-z tutorial on how … Read more
The easiest way: create a page template that only includes the search form (get_search_form()) create a page and assing the template In the href attrib of the iframe, instead of put the url for searchform.php put the url of the page Pretty easy, but you need a query to get the page. A more performant … Read more
Adding the following code in functions.php customize WP search for title only function search_by_title_only( $search, &$wp_query ) { global $wpdb; if ( empty( $search ) ) return $search; // skip processing – no search term in query $q = $wp_query->query_vars; $n = ! empty( $q[‘exact’] ) ? ” : ‘%’; $search = $searchand = ”; … Read more
You are missing the curly brackets {} around your query statements so the query is modified regardless of the if statement. So try modifying your code to have something like if( is_search() ) { $fields=”…”; return $fields } same thing with your $join variable Remember that while using if without brackets is acceptable for single … Read more
You can use ‘pre_get_posts’ filter hook and change the search query. function wpse_search_filter( $query ) { if ( $query->is_search ) { $query->set( ‘post_type’, array(‘product’) ); // setting post type as product (for woocommerce only) } return $query; } add_filter(‘pre_get_posts’,’wpse_search_filter’);
This code should work OK, but… There are some problems with it. Let’s break it apart and add some comments. function searchcategory($query) { if ($query->is_search) { // Checking only for is_search is very risky. It will be set to true // whenever param “s” is set. So your function will modify any wp_query with s, … Read more
When you code get_search_form() WP search searchform.php in your theme root and print all inside that file. And you can create searchform.php inside your theme root and insert this: <form role=”search” method=”get” action=”<?php echo home_url(“https://wordpress.stackexchange.com/”); ?>”> <fieldset> <input type=”text” name=”s” value=”<?php the_search_query(); ?>”> <button></button> </fieldset> </form> That basic search form. Then code <?php get_search_form() ?> … Read more