Search function works improperly

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

How to make a search form?

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

Changing search slug from + to – (hyphen)

PHP’s urlencode() function replaces spaces with +s, so that’s why that’s happening for you. WordPress provides the sanitize_title() function, which is used (among other things) to generate a post slug from the post’s title. /** * Change search page slug. */ function wp_change_search_url() { if ( is_search() && ! empty( $_GET[‘s’] ) ) { wp_redirect( … Read more

Search in Two Categories

Basically you don’t really want search, but separate page that will list post on specific condition? You can create template for a page with Loop that will query for posts, belonging to both categories, using category__and parameter.

More than one search results page template

You could make a page template http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates And then you could post some data via $_GET /search2/?search=xxx to that page and do a custom wp_query where you use ‘s=” . $_GET[“search’] http://codex.wordpress.org/Class_Reference/WP_Query Something like this: $args = array( ‘s’ => $_GET[‘search’] ); $the_query = new WP_Query( $args ); // The Loop while ( $the_query->have_posts() ) … Read more

Alphabetical search

Yes. Do a SQL query for posts using LIKE ‘x%’, where x is your letter. Here’s a simple example: global $wpdb, $post; $letter=”a”; // or $_GET[‘letter’]… $query = “SELECT * FROM {$wpdb->posts} WHERE post_name LIKE %s”; $query = $wpdb->prepare($query, $letter.’%’); $results = $wpdb->get_results($query); // note that variable name must be $post, // because you need … Read more

Display just child pages of a certain page in search results

Try the following approach. Get the page using get_page_by_path() http://codex.wordpress.org/Function_Reference/get_page_by_path $page = get_page_by_path( ‘university-guide’ ); $search_query[‘post_type’] = ‘page’; $search_query[‘post_parent’] = $page->ID; The following snippet was taken from Codex page: Creating a search form http://codex.wordpress.org/Creating_a_Search_Page global $query_string; $query_args = explode(“&”, $query_string); $search_query = array(); foreach($query_args as $key => $string) { $query_split = explode(“=”, $string); $search_query[$query_split[0]] = … Read more

Highlight Search Results in Function.php

You can try running the function early so that it runs before the more link is created. add_filter(‘the_excerpt’, ‘highlight_search_term’,1); add_filter(‘the_title’, ‘highlight_search_term’); But I don’t think that solves the deeper problem, even if it were to work. That function is pretty crude and it will replace inside URLs and inside tag attributes, which it should not … Read more