tags:

views:

16

answers:

1

i am having website www.xyz.com in wordpress,i want to implement search option in the home page it should be in the manner when a user search for state or thorough pin code he should get the result, so kindly let me know how do the same and what is the codding .

i am using coding is: Find a Yoga Class in this City:
this for search, and i want backend code where i can call function from the database, and where to be implemented

A: 

From the sounds of things, you want to enable a search of Yoga classes based on a zip-code or state. This can be a bit tricky, actually, but it can be done.

Custom Post Type

First of all, you'll want to create a custom post type called "Yoga Class" for your classes. This will essentially be a separate category of posts with special capabilities. Each class can have a "Description" field, a "Location" field, a "Time" field, an "Instructor Biography" field, etc. It really depends on what information you want to provide for each class.

Here's a great tutorial on creating and working with custom post types: Custom post types in WordPress.

Custom Taxonomy

To enable searching and sorting, you'll need to categorize your Yoga Classes in a meaningful way. Since WordPress 2.8 came out, we've supported custom taxonomies for posts, pages, and even for custom post types. It's a way to divide content into meaningful groups, making it easier to search and view content based on custom fields.

You'll need two custom taxonomies: State, and Zip Code.

Here's a great tutorial on creating and managing custom taxonomies: Custom taxonomies in WordPress 2.8

Custom Search

Your search box will basically search through your custom post type (Yoga Class) for any entries with a State or Zip Code taxonomy term matching your search criteria. So if you search for a class in Tennessee, your search will look for all entries where post_type=yoga_class and where state=tennessee or zip-code=tennessee. If you search for a class in zip code 90210, it will search for all entries where post_type=yoga_class and where state=90210 or zip-code=90210.

This is by far the easiest way to search for entries based on zip codes. If you want something that can search for classes in nearby zip codes rather than exact matches, I recommend reading up on a similar question over at WordPress Answers.

EAMann