0

I'm trying to show search results only for a specific custom post type, my code is simple and I already tested it successfully on some wordpress sites I made, but in this case (buddypress) looks like it is not working.

Here is my form:

<form id="vendor-search" action="<?php bloginfo('siteurl'); ?>" method="get">
<h5>Search for vendors</h5>
    <input type="hidden" name="post_type" value="vendors" />
    <label for="s" class="screen-reader-text">Search for:</label>
    <input type="text" id="s" size="23" name="s" value="" />
    <input type="submit" value="Search" id="searchsubmit" />

So I set this hidden input:

<input type="hidden" name="post_type" value="vendors" />

and then I get a correct URL when searching, something like:

mywebsite.com/?post_type=vendors&s=Marketing

but on displayed results it is including all kind of posts and pages...

Any ideas about what can this be?

Thanks a lot!

1 Answer 1

0

Check out customizing the WP template search.php... you could detect the custom post type query and build your query inside the search.php template as needed.

IF query = custom post type THEN

Customize query using WP_query

ElSE

Show Standard search results

END IF

Hope that helps.

2
  • Yes, that might work, let me check on this and get back to you. Thanks!
    – Jaypee
    May 29, 2012 at 17:31
  • Hmmm, I'm trying several ways, but can't get the right code, would you mind to give me a clue of how I should set? I've never customized a search.
    – Jaypee
    May 29, 2012 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.