Redirect wordpress search query if its a tag

To do it in query handling stage, may use request hook which is when WordPress query is being setup. The term link is recommended by @Jacob Peattie using built-in get_term_link() instead of building it manually for more flexibility and error-proof. add_filter( ‘request’, ‘ws366006_check_request_query’ ); function ws366006_check_request_query( $query ) { // var_dump($query); // redirect checking if( … Read more

Search results – 404 error after hitting enter

It appears your search is going to https://youthtalkedinburgh.co.uk/?post_type[]=&s=sport instead of the (more proper) https://youthtalkedinburgh.co.uk/?s=sport, which works. Looking at the source, it appears your search form looks like this (simplified): <form … > <input type=”hidden” name=”post_type[]” value=””> <input name=”s”… > … </form> That <input type=”hidden” name=”post_type[]” value=””> input field doesn’t seem to belong. I suspect either … Read more

How to exclude woocommerece product category in search results?

function exclude_product_category( $query ) { if ($query->is_search()) { $tax_query = (array) $query->get(‘tax_query’); $tax_query[] = array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array(‘excluded-category’), ‘operator’ => ‘NOT IN’ ); $query->set(‘tax_query’, $tax_query); } return $query; }

Search to include external content

For searching among your posts through Advanced custom fields, use fallowing query: $args = [ ‘post_type’ => ‘post’, ‘meta_query’ => [ ‘relation’ => ‘OR’, [ ‘key’ => ‘NAME_OF_ACF_FIELD’, ‘compare’ => ‘like’, ‘value’ => ‘%’.$search_value.”, ] ] ]; $items = new WP_Query($args); while($items->have_posts()) { $items->the_post(); the_title(); } This will output the titles that matches our search … Read more

Showing search results on a page

Please refer to the updated comment. You have to do some changes to the search functionality by default. First, if you want to use different templates for each kind of search, you can add conditions in the search.php file. if(isset($_GET[‘search-type’])) { $type = $_GET[‘search-type’]; if ($type == ‘global’) { load_template(TEMPLATEPATH . ‘/search-global.php’); } elseif ($type … Read more

Get search result count in plugin

Let’s what can be done. Try the bellow code. First I’m checking if it’s search query. Then trying to get the count from global query. function search_count(){ if(is_search()){ global $wp_query; $not_singular = $wp_query->found_posts > 1 ? ‘results’ : ‘result’; echo $wp_query->found_posts . ” $not_singular found”; } }