Redirect To Post If Search Results Return One Post

Wordpress has a built in search functionality which allows your visitor to easily search for posts on the blog. It can search for keywords in the post title and in the post content.

When a search is performed WordPress will use the search.php file to display you the results. You can customise this page to display the entire list of posts returned from the WordPress database.

The problem is that if WordPress returns only one post in the search results it will still take you to the search.php file and display a list of posts, well the one post.

Below is a WordPress snippet you can add to your functions.php file to check how many posts are returned by the search, if it returns one post then performs a redirect to the post. Read more...

Wordpress has an built in search facility which will allow you to search for keywords within your posts search in either the post title or the post content.

In order for WordPress to perform a search on your posts and return the search results page it will need to have a $_GET variable of s. When WordPress finds this query string parameter it will perform a search on the value of this parameter.

You can't ask your users to type in a query string of ?s=search%20wordpress whenever they want to search for something so you need to provide them with a search form, where they can type in the keywords, hit search and we will return a list of posts for them to choose from. Read more...

Wordpress

Wordpress comes with the functionality to create menus in the dashboard area, from here you can select pages or custom custom menu items to make up your menu.

Menus are normally going to be display at the top of the page to give the visitor easy access to your main pages. But this top navigation bar is also a good place to have your search box so if people can't find what they are looking for then they can use your search box. Read more...

Keywords

There may be times when you have a little rant of make a mistake in a post and want to exclude this from the in-built WordPress search functionality.

There is a way you can intercept the WordPress search functionality and exclude certain posts from being displayed. All you have to do is find out the post ID and add it to the following function in your functions.php file.

First you need to check is you are currently on the search page by checking if the is_search parameter is set to true. If you are currently on the search page this will be set to true and you can continue to exclude certain post Id's from the page.

You should also check to see if WordPress is currently processing the main query by calling the method is_main_query(). The is main query method will process any queries made to the pre_get_posts hook.

Once these are checked then you know that the query being ran will be the search query from WordPress.

function exclude_posts($query) {
    if ($query->is_search && $query->is_main_query()) {
        $query->set('cat','110, 201, 254, 302');    //Change the numbers to your post IDs
    }
    return $query;
}

add_filter('pre_get_posts','exclude_posts');

Since WordPress version 3.0 you can now create your own custom post types. WordPress already comes with post types for things such as posts, pages, attachments, revisions and menus.

Custom Post types allow you to create your own content item. These are commonly used for portfolio slides and news articles.

The problem with custom post types is that they are not included in the WordPress search functionality you can only see posts and pages.

Search Read more...

Wordpress WordPress comes with it's own in-built search functionality which can search the title and content of all your posts on your WordPress site.

To perform a search on your WordPress site all you have to do is create a search form which posts a GET parameter s to the home page of your WordPress site.

http://www.paulund.co.uk/?s=wordpress

Read more...

Search By Default wordpress search functionality will search the entire content of the WordPress post. What if you don't want WordPress to search the entire content of the post, you can actually change the search functionality to only search the post titles.

Copy the following into your functions.php file or create a plugin with this snippet in to make sure WordPress only searches on post title. Read more...

Wordpress

The WordPress WP_Query functions allows you to pass in an array of parameters to search your posts on your blog.

You can pass in multiple different parameters to narrow down the posts to get exactly what you need.

But with this massive flexibility you can get confused as to what you can exactly query on. Read more...

The purpose of the robots.txt file is to direct search engines to where they can index and where they are not allowed to index.

It is recommended by all search engines to use this robots.txt file so that they don't waste time and resources crawling and indexing files which you don't want them to be indexed.

Here is what WordPress recommends your robots.txt file to look like. Read more...

In this tutorial we are going to style text boxes and buttons to create pretty search forms. We are going to create three forms which will match the image above.

The three styles are dark grey, light grey and a lighter grey just like the image below.

Search Boxes

The HTML

Each of the search forms will have a textbox and a button which we can submit the search. Read more...