Refine/Filter the Search Results by Category

I am currently creating the process of a function which allows one to refine results, Namely by category. Similar to themeforest.net refine the search results.

When i gave as search term “Hello” and search in Category A, D, F, E, than are the filter displayed by the results (in those categories only where the search indeed available), and then when one press on the filter by Category D, then refines it the search results and shows only the result from the Category D.

Read More

My only problem is that when my Url shows like this and i search by this cats:

...&orderby=relevance&order=desc&adv_tag=0&adv_cat_52=on&adv_cat_57=on&adv_cat_58=on&adv_cat_53=on&adv_cat_56=on&...

then is the problem, that when i click on the refine filter, that this cats in the url not removed, but the clicked cat is added to the url. when i remove the other cats, then works as excepted. With which Rewrite/Remove Rule/Function can i solved this problem. I think with remove_query_arg or?

<?php 

$filter_cats=array();
$i=0;

            while (have_posts()) : the_post();
                foreach((get_the_category()) as $category) {

$id = $category->term_id;
$cat = 'adv_cat_'.$id.'';

$base_url = remove_query_arg(array($cat));

$url = $base_url;

$url = $url;


$categores =  '<a href="'.$url.'&adv_cat_'.$category->cat_ID.'"><i>'.$category->cat_name.'</i></a>'; 

                $filter_cats[$i] = $categores; 
                $i++;
                }
            endwhile;   



$filter_cats = array_map("unserialize", array_unique(array_map("serialize", $filter_cats)));




//Einträge zählen

$anzahl=count($filter_cats);



$i=0;
while($i<$anzahl){


        echo"<fieldset>{$filter_cats[$i]}</fieldset></br>";
        $i++;
}

Related posts

Leave a Reply