make link to search page

Just like cybmeta in the answer you are linking to said: see Creating a search page in the codex. Read it carefully. Create a Template like described, add a new page in the backend and choose as template your new search-template, that is now in the template-dropdown. Now you can set a link to this … Read more

Redirect to a page while maintaining search query parameters without causing an infinite loop

I achieved this with a couple filters: add_filter( ‘query_vars’, ‘addnew_query_vars’, 10, 1 ); function addnew_query_vars($vars) { $vars[] = ‘r’; // var1 is the name of variable you want to add return $vars; } function redir_cat_match($a) { global $wp_query; if ($wp_query->is_main_query() && $wp_query->is_search()){ if ($wp_query->query_vars[‘s’] != “”){ if ($_GET[‘r’] != ‘0’){ if (!empty($wp_query->posts[0])){ $s_value = $wp_query->query_vars[‘s’]; … Read more

ajax stopped working when not logged in wordpress

Try to output the debug query Find fragment $the_query = new WP_Query( array( ‘posts_per_page’ => 5, ‘s’ => esc_attr( $_POST[‘keyword’] ) ) ); if( $the_query->have_posts() ) : Replaced by $the_query = new WP_Query( array( ‘posts_per_page’ => 5, ‘s’ => esc_attr( $_POST[‘keyword’] ) ) ); echo (string)$the_query->request; if( $the_query->have_posts() ) : Perhaps some hooks are triggered … Read more

Create a post automatically if search result has zero results

Assuming you are using the standard WordPress search, you can get the searched number with get_search_query So this code will create a new draft post if no results were found for the search: $match = get_page_by_title( sanitize_title( get_search_query() ), OBJECT, [‘post_type’ => ‘post’] ); if ( empty( $match ) ) { wp_insert_post( [‘post_title’ => sanitize_title( … Read more

Search function – problem with whole words

Exact means exactly that – the whole field must match, not just a word in the field. To get whole words that are part of the field, remove ‘exact’ => 1 Add this if ($_POST[‘terms’]) { $keyword = sanitize_text_field( $context[‘terms’] ); $keyword = ‘[[:<:]]’ . $keyword . ‘[[:>:]]’; $context[‘posts’] = Timber::get_posts(array( // other params here … Read more

Search doesn’t return anything

Might not be the real cause, but you have a JS error due to badly formatted JS – the following lines: <script type=”text/javascript”> jQuery(document).ready(function( $ ){ jQuery(“a[href=’#aiwoosearch#’]”).attr(‘onclick’, ‘parentNode.submit();’); jQuery(“a[href=’#aiwoosearch#’]”).attr(“href”, “javascript:;”); }); </script> Those quote marks are wrong “ & ‘ try ” & ‘ instead and test again with your JS console open in inspector.