Hello,
How can I search for a custom post in a custom tyxonomy, or how do I have to build the GET-varable.
I've got a custom post type 'product' and a custom taxonomy 'product group'. Now I need a search form, with the posibility to search for a product in a choosen product group.
To do so, I use this Code:
<form id="searchform" action="<?php bloginfo('url'); ?>/" method="get">
<input id="s" maxlength="150" name="s" size="20" type="text" value="" class="txt" />
<input name="post_type" type="hidden" value="<?php echo $postType ?>" />
in <?php wp_dropdown_categories( array( 'taxonomy' => 'as_tax_product') ); ?>
<input id="searchsubmit" class="btn" type="submit" value="Search" />
</form>
If I search for a existing product with the right product group choosen, I get no result, but this messages:
Notice: Trying to get property of non-object in C:\Program Files\xampp\xampp\htdocs\wp_shop\wp-includes\general-template.php on line 1652
Notice: Trying to get property of non-object in C:\Program Files\xampp\xampp\htdocs\wp_shop\wp-includes\general-template.php on line 1653
If I don't send the post_type, I get more Notices. this is something I don't understand, because I limit the search with:
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'as_post_product');
}
return $query;
}
add_filter('pre_get_posts',array($this, 'SearchFilter'));
All of the Notices mention lines in the code, which have something to do with the category, so I suppose, I cannot query for my custom posts in this way.
With the form above, the GET varable looks like:
http.../?s=ball&post_type=as_post_product&cat=18.
the SQL Query looks like:
SELECT ..... WHERE 1=1 AND 0=1 AND...
Everything in the query is OK only the 1=1 AND 0=1 I don't understand, and I think, the 0=1 has to do with the problem as well.
I hope, I posted all info needed.
Every tip would be nice.
Greets Paka