Need help for "advanced" search functionality
Hi,
I am developing a site where we have two main categories:
For sale, Wanted.
Each of these has many sub categories, and we need to be able to perform a search on these sub cats respectively.
Now, when using the default search engine that comes with
WP this would be accomplished by passing a comma separated string containing the IDs of the children of the two main categories to the $cat parameter - and have a radio button select in the search form like this:
Code:
<input id="btn_selges" type="radio" name="cat" value="<?php echo jai_get_subcat('1'); ?>" checked> <lable>Til salgs</lable>
<input id="btn_kjopes" type="radio" name="cat" value="<?php echo jai_get_subcat('5'); ?>"> <lable>Ønskes kjøpt</lable>
In functions.php the following function returns the list of subcats:
Code:
// jai_get_subcat: returns a comma separated list of sub-categories
function jai_get_subcat($parent) {
$categories = get_categories('child_of='.$parent);
$catlist = '';
foreach ($categories as $cat) {
$catlist.= $cat->cat_ID.',';
}
$catlist .= $parent; // in case someone has put an ad in the parent cat
return $catlist;
}
However, this does not work with the CP-search engine implemented in theme-functions.php. If I comment out the filter/action registration:
Code:
// search on custom fields
// add_filter('posts_join', 'custom_search_join');
// add_filter('posts_where', 'custom_search_where');
// add_filter('posts_groupby', 'custom_search_groupby');
and comment out the check to only display post in $cat if $cat is set in the search.php:
Code:
<?php while(have_posts()) : the_post() ?>
<?php //if (!in_category($cat) && $cat != 0) continue; // only display posts in cat if cat is set ?>
... I can get it to work. But now I am not searching the custom fields anymore as this is using the default search engine from
WP.
I would like to know how to change the SQL query in the CP search engine so that it accepts a list of categories IDs to search.
At present, CP302 can display results for a search in 1 category, but it is not really a search! it is a refine search done in search.php. It still searches through all categories for search string $s, which is not very smart if the system has a lot of categories and a lot of content.
Thanks for a very good system! It only needs some more advanced search functionality and it will be fantastic! I will need to do this for a client and would give you the code later if you could help me with the SQL stuff described above.
you can view a test version of the system here,
http://jai.no/okofunn/v4/ and it shows that you can really customize the CP theme
thanks,
Jaidev
@ Jai Design