Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Want search to redirect to a page and display specific results WordPress

  • SOLVED

Hello,

I'm building a website for a city that has a community/business directory. I've added a custom post type for the directory listings, and now need an elegant way to search those listings. Here is the link:

[[LINK href="http://casselton.com/dev"]]Development Site[[/LINK]]

We have a search bar in the top right corner, and when a visitor enters a value we'd like the following to happen:
1. Redirects to [[LINK href="http://casselton.com/dev/community-directory-categories"]][[/LINK]]
2. Only searches the business names and categories on this page (no other posts or pages, etc.)
3. List the search results (which I can style)

Does anyone have experience with this?

I'm using the default WordPress searchform.php
Link to my search.php: [[LINK href="http://pastebin.com/E65jUA2n"]]Pastebin[[/LINK]]
Link to my custom post type page php: [[LINK href="http://pastebin.com/eFYkBhg1"]]Pastebin[[/LINK]]

Thank you,
Dave

Answers (2)

2011-11-16

Luis Abarca answers:

Hi schmidty54, as i undertand you just only need to filter the search result to a specific post type.

You can add a hidden field with your post type in your search form to get a ulr like this.

[[LINK href="http://casselton.com/dev/?s=test&post_type=community_listing"]]http://casselton.com/dev/?s=test&post_type=community_listing[[/LINK]]

i can help with this if you send me login/ftp details via PM.


Luis Abarca comments:

Something like this ?

http://casselton.com/dev/community-directory-categories?q=adm


Dave Schmidt comments:

Yes, I think that woud work just fine.

Dave


Luis Abarca comments:

I'm glad it helps Dave, let me know if you have any issue


Dave Schmidt comments:

Hi Luis,

I see you've been able to redirect the search. That's great, and thank you!

Are you able to help me add my custom taxonomies to the search query? So I just want the visitor to be able to search my custom post types and custom taxonomies.

Thanks!
Dave


Luis Abarca comments:

OK Dave.

As we are using a custom page for the search, we can add that filters in in the args of WP_Query, we need to pass the post_type argument when we use the default search Wordpress


Dave Schmidt comments:

Luis,

For an extra $10 can you write the query for me?

Right now I just copied and pasted search code from Ian Stewart's blog. I pasted the code on the custom page. I'm just not that comfortable writing custom queries. All I really want is the following:

1. Text that reads: "Search Results for: " with the search term displayed.
2. Results based on either category or post title.

We're soooo close Luis! I'm sure you can help me with this!

Thanks,
Dave


Luis Abarca comments:

Yep Dave

I'm trying to edit the files, but it seems you moved the folder to another place :S

2011-11-16

Sébastien | French WordpressDesigner answers:

Dave, i'm french. So i need to know if i understood your question.

You want a specific page "result of search" which displays only the business names and categories (no others pages)

That's it ?

i dont understand the first point "redirects to".
And the third ("List the search results"). Is it not the same thing ofthe point 2 ?


Dave Schmidt comments:

Hi Sébastien,

Once you type in your search query and press enter (or click on the magnifying glass), I'd like WordPress to take the visitor to this page: [[LINK href="http://casselton.com/dev/community-directory-categories"]]community-directory-categories[[/LINK]]

I'd like the search results to display on this page, not the typical search page. So if you look at [[LINK href="http://casselton.com/dev/community-directory-categories"]]community-directory-categories[[/LINK]], I'd like the search results to appear above the content. Does that make sense?

Thank you for replying!

Dave


Sébastien | French WordpressDesigner comments:

oki understand
and each result is composed by what ?

in your page i see


AGRICULTURE

ADM Edible Bean Specialities
1804 Front St. Casselton, ND 58012 347-5321
[email protected] www.adm.com

Dalrymple Farms
710 Front St. Casselton, ND 58012 347-4291
www.fargo-history.com/early/dalrymple.htm





what is "agriculture" ? a categorie ?
"ADM Edible Bean Specialities" is a title
athers informations are values of differents custom fields, that's it ?


Dave Schmidt comments:

Agriculture is a custom taxonomy named "listing_category".
ADM Edible Bean Specialities is the title of a custom post type named "community_listing".
And yes, the information being populated is added via custom fields.


Sébastien | French WordpressDesigner comments:

and you want an url like that

http://casselton.com/dev/community-directory-categories?s=bonneville

or like that

http://casselton.com/dev/community-directory-categories

for the result of the search "bonneville"

?


Dave Schmidt comments:

I think http://casselton.com/dev/community-directory-categories?s=bonneville would probably make more sense.

Thanks,
Dave


Sébastien | French WordpressDesigner comments:

so i think that you have your solution :
[[LINK href="http://casselton.com/dev/community-directory-categories?q=adm"]]http://casselton.com/dev/community-directory-categories?q=adm[[/LINK]]
:-)