Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to build an advanced search form by post type.

For example...

I have custom Post Type : Locatie Taxonomy : locatii

I have categories in PostType :

Categories:

-Orase - Arad - Alba....

-Tip - Puncte de livrare - Gaze Medicale

I want to get all post in that categories..

For example i select Arad and Gaze Medicate... and shoud apear me all the Medical Point for city arad.

<form method="get" name="searchform" action="<?php bloginfo('url'); ?>/">

<fieldset>
<legend>Centre de distributie:</legend>
<form>
<table width="500" border="0" cellpadding="0">
  <tr>
    <td width="135"><b>Selecteaza oras :</b></td>
    <td width="359"><select name="locatie">
<option value="alba">Alba</option>
<option value="arad">Arad</option>
<option value="arges">Arges</option>
<option value="bacau">Bacau</option>
</select>
    </td>
  </tr>
</table>


<div class="ti"><b>Limiteaza cautarile</b></div>
<div class="linie"></div>

<table width="500" border="0" cellpadding="0">
  <tr>
    <td width="20"><input name="produs" value="1" type="checkbox"></td>
    <td width="160">Punct de livrare</td>
    <td width="25"><input name="produs" value="1" type="checkbox"></td>
    <td width="109">Parteneri logistica</td>
    <td width="35"><input name="produs" value="1" type="checkbox"></td>
    <td width="137">Agenti</td>
  </tr>
  <tr>
    <td><input name="produs" value="1" type="checkbox"></td>
    <td>Gaze Medicale</td>
    <td><input name="produs" value="1" type="checkbox"></td>
    <td>Propan</td>
    <td><input name="produs" value="1" type="checkbox"></td>
    <td>Refrigerenti</td>
  </tr>
</table>
<div class="sub">
<input class="art-button" type="submit" name="search" value="<?php _e('Search'); ?>" />
</div>

</fieldset>
</form>
share|improve this question
add comment

2 Answers

In your search form, add an input with name="post_type" and value="customposttypehere".

You can either have this as a hidden input or a text entry or a combobox or radio buttons etc, so long as it's inside the search form.

The same is true for any other query vars like post_type etc that you would normally put in WP_Query

share|improve this answer
add comment

You'll need to look into pre_get_posts(). A great starting tutorial on this is by Pippin Williamson, Using pre_get_posts to Modify Queries for Meta Data and More (helped me out immensely).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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