Crocoblock / suggestions

The suggestions for CrocoBlock project
195 stars 78 forks source link

💡 [Jetsmartfilters] Redirect taxonomies to search page as filters #3376

Open nreljed opened 3 years ago

nreljed commented 3 years ago

In this problem we will take the example of cardealer

taxonomies

I'm trying to redirect taxonomies to my search archive /cardealer/catalog / as filters

In this way when I add and click on "Clear" of active tags widget

I can immediately continue the search with other filters and types.

Otherwise I will be stuck in the filters with the chosen taxonomy for example cardealer/types-of-transport/water-transport/

The solution I use with another site under facetwp it was this one

add_filter ('term_link', function ($ termlink, $ term, $ taxonomy) {

// taxonomy types of transport
if ('types-of-transport' == $ taxonomy) {
        $ termlink = trailingslashit (get_home_url ()). '/catalog/?_type='. $ term-> slug;
    }
    return $ termlink;
}, 10, 3);

This code is supposed to redirect the taxonomy to /cardealer/catalog/

Then the magic missing line ?_hello_its_me_type= activate the filter

Then without having to load or leave the page or create a big button "return to catalog" you just have to click on "Clear" and start a new search with all the filters which will be available now.

Problem..jetsmartfilters does not show the search url structure .. so i cant figure out which i need to insert

https://demo.crocoblock.com/cardealer/catalog/?_water_transport ???

While waiting for someone to solve this mystery and tell us which line of code to insert or come up with a simpler solution to redirect taxonomies as filters to the page / archive catalog.

EDIT :

To understand what I'm talking about, normally the URL search structure should be like this realhomes wpresidence

problem! we see nothing.. so I don't understand what is happening.. I don't know how to activate this (show me URL) or if it is planned in a future update..

nreljed commented 3 years ago

I did another test with real estate exemple I don't know what happened .. now I can see the url search structure of jetsmarfilers which now allows me to use my snippet

add_filter('term_link', function ($termlink, $term, $taxonomy) {
    // taxonomy type
    if ('property-type' == $taxonomy) {
        $termlink = trailingslashit(get_home_url()) . 'properties/?jsf=jet-engine&tax=property-type:' . $term->slug;
    }
    return $termlink;
}, 10, 3);

which gives us this localhost/mysite/properties/?jsf=jet-engine&tax=property-type:office not working

but I notice that jetsmart uses id instead slug and it's not good .. he does not understand my snippet ..

localhost/mysite/properties/?jsf=jet-engine&tax=property-type:10 working

if someone has a trick to slove this id problem, please share

Edit :

the correct code just replace $term->slug;with $term->term_id;

Edit (30-09-2021) to keep the snippet functional with jetsmartfilters 2.3.2

add_filter('term_link', function ($termlink, $term, $taxonomy) {

    // taxonomy type
    if ('property_type' == $taxonomy) {
        $termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine:archive&tax=property_type:' . $term->term_id;
    }

    // taxonomy city
    if ('property_city' == $taxonomy) {
        $termlink = trailingslashit(get_home_url()) . 'property/?jsf=jet-engine:archive&tax=property_city:' . $term->term_id;
    }

    return $termlink;
}, 10, 3);

this exercise is not over. what to consider and explore?

my inspiration and example https://www.airbnb.com/

fabio323ti commented 3 years ago

Thanks you for code, is working fine. many thanks..

hope crocoteam enable full structure of permalink/ajax selection... filter must work on default /shop/ permalink , override category permalink added to it.. its ajax purpose. hope they will fix soon.