Creating a custom search form

Here’s an option. Give a more specific name e.g. custom_search_form to your submit button: (…) //First a submit button $output .= ‘<input type=”submit” class=”submit” name=”custom_search_form” id=”searchsubmit” value=”submit” />’.”\r\n”; Then you can add this to your functions.php file: add_action( ‘parse_request’, ‘my_custom_search_form’ ); function my_custom_search_form($query) { //return if it not our custom search form if ( ! … Read more

changing behaviour of get_search_form

you don’t need to add another function to get the search form. If you want to change the look of the search form or add another items you’ll have to add the searchform.php to your theme. It could look like this: <form role=”search” method=”get” class=”search-form” action=”<?php echo home_url( “https://wordpress.stackexchange.com/” ); ?>”> <input type=”search” class=”search-field” placeholder=”Suchen … Read more

How to conditionally pass a parameter to wordpress search to limit post types?

If you have a “natural” artwork archive (typically setting has_archive to true in your register_post_type() arguments), you already have the functionality in place: http://example.com/artwork/?s=query …assuming artwork is your archive slug, WordPress will search only artwork for “query”. Just set the action attribute of the search form to the archive URL, like so: <form action=”<?php echo … Read more

Temporarily storing main search result

The way I see it, you have three options: Store the global search data in $_SESSION Store the global data in a transient Run the query twice, with & without the post type filter I tried storing the array in a global variable and as soon as the page refreshes with the refined search results, … Read more

How to exclude events (custom posts) from search, if the start date has already passed?

This works, when I put it in functions.php. function wpq_modify_search( $q ) { if ( ! is_admin() && $q->is_main_query() && $q->is_search() ) { $meta_query = [ ‘relation’ => ‘or’, [ ‘key’ => ‘_event_start_date’, ‘value’ => current_time( ‘mysql’ ), ‘type’ => ‘DATETIME’, ‘compare’ => ‘>=’, ], [ ‘key’ => ‘_event_start_date’, ‘compare’ => ‘NOT EXISTS’, ], ]; … Read more

Search for multiple tags?

Well, I got it working by making my own own parse php as follows: parse.php <?php $tags = $_POST[‘tag’]; $search = $_POST[‘s’]; $count = count($tags); $i = 0; if(!empty($search)) $uri = “https://example.com/?s=$search&”; else $uri = “https://example.com/?tag=”; foreach($tags as $name=>$value) { ++$i; if($i !== $count) $uri .= $value.”+”; else $uri .= $value; } header(“Location: $uri”); exit; … Read more

Search result page redirect ex.com/?s=searchterms to ex.com/searchterms

Write this in your theme’s functions.php. Hope this helps you out. function code_search() { if ( is_search() && strpos($_SERVER[‘REQUEST_URI’], ‘/wp-admin/’) === false && strpos($_SERVER[‘REQUEST_URI’], ‘/search/’) === false ) { wp_redirect( get_bloginfo(‘home’) . ‘/search/’ . str_replace(‘ ‘, ‘_’, str_replace(‘%20’, ‘_’, get_query_var(‘s’)))); exit(); } } add_action(‘template_redirect’, ‘code_search’);