Skip Navigation

[Gelöst] view Query Filter nor search parameters does not filter the results correctly

This support ticket is created vor 5 Jahre, 11 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Dieses Thema enthält 7 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von davidZ-4 vor 5 Jahre, 10 Monate.

Assistiert von: Nigel.

Author
Artikel
#915071
filter.JPG

I am trying to: pass a search parameter using url parameters to display a set of matching products

Link to a page where the issue can be seen: versteckter Link

I expected to see: the results on the page versteckter Link filtered based on the url parameters

Instead, I got: products that are not in the category of the value in the url parameter display and other filters are not working as well

see enclosed filter for the view settings.

you can test on the test page: versteckter Link to see available products and see the possible alternatives in the url search parameter but when you look into the product taxonomy value against the filter there is no match.

repro steps on the test page
select gender = female
click search - search results render versteckter Link
click the first product on the lest "Cypress DX test name"
the product page render - versteckter Link
click the Spec tab
you can see that the gender is set to male and not female.
the same goes for age group.

the URL parmeters i'm working with are:
pr - price - set by woocommerce product price
bt - bike type - set by woocommerce product category
ag - age group - woocommerce taxonomy set up with toolset
gn - gender - woocommerce taxonomy set up with toolsett
yr - year - woocommerce taxonomy set up with toolset

the PR filter works fine but the other does not.

please advise,
thanks,

David

#915177

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+01:00)

Hi David

Can I take a look in the backend to get a better idea of what's happening?

This is a staging site, right? I might play with a few settings but I won't make any significant changes without reporting back to you.

#915638

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+01:00)

Sorry David

The credentials don't work, I can't log in. Can you try again?

#916261

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+01:00)

Hi David

I modified the output of your View to show the taxonomies to make it easier to see whether the results are correct are not.

Here on the test site it is clear it is not working: versteckter Link

It is not obvious why, so I created a new test View with filters to check that it should be working with the existing data, and it does: versteckter Link

It works even if I delete the filter controls.

So there seems to be something very specific to your View that I can't readily identify.

Might I suggest you start with a new View, or edit mine, and replace the View you are currently using?

#916471

Hi Nigel,

I just pinpoint the issue.
In short, I created a new view on my stage environment and worked step be step to test it. it all worked fine and as intended until I set the view "Ordering" to a custom field "order by = Field - Bike Score" AND use the following code to display only simple products on the page.

add_filter( 'wpv_filter_query', 'func_filter_simple_products', 10, 3 );
function func_filter_simple_products( $query_args, $view_settings, $view_id ) {
       
    if ( $view_id == 585) { // edit the id
   
        $query_args['tax_query'] = array(
          array(
            'taxonomy' => 'product_type',
            'field' => 'slug',
            'terms' => array('simple'),
            'operator' => 'IN'
          ));
    }
   
    return $query_args;
}

if the order by is set to "Post Date" the URL parameters works just fine with the code above. the minute I set it to the custom filed "order by = Field - Bike Score" the query string is been ignored.
the code above is located under snippets under the name "Get Product Type".

Thanks,

David

#916557

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+01:00)

Hi David

I didn't see the same as you on your staging site.

If I disable the code snippet the View returns no results.

If I change the ordering to just use post title it makes no difference to the View results, they are still wrong.

It will be easier for me to debug this locally, so I'm taking a copy of your site and I'll get back to you later.

#916702

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+01:00)

Hi David

The custom code you added to modify that View was written at a time when you weren't adding other taxonomy filters.

Now that you have the current code replaces the taxonomy query generated by the filters, instead of being appended to it.

You can fix that with a minor tweak to the custom code, by editing this line so that it includes empty square brackets (so that the array element is appended to existing elements):

        $query_args['tax_query'][] = array(
#916731

Thanks Nigel,
Your solution solved the issue and things are working as they intended t.
I highly appreciate your help with this.
Have a great weekend,
David

Dieses Ticket ist jetzt geschlossen. Wenn Sie ein Toolset Kunde sind und Hilfe benötigen, eröffnen Sie bitte ein neues Support-Ticket.