Skip Navigation

[Resolved] Filter results of wpv_filter_query

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to know how to programatically modify the views query.

Solution:
The views query can be modified by using the hook below.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 3 years, 6 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by wesselK 3 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#2099213

Tell us what you are trying to do?

I am trying to write some PHP code that filter the results after the view query has been executed. But I can't seem to find a hook within the documentation that does this. So to be clear, I want to filter the result using some custom PHP code right before they are displayed on the page.

So what I am looking for is a list of all $items inside the view that I can loop through and change.

Is there any documentation that you are following?

https://toolset.com/documentation/programmer-reference/views-filters/

Is there a similar example that we can see?

Not that I can think of.

What is the link to your site?

Currently I am working local

#2099275

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Wessel,

Thank you for getting in touch. The best hook to use for this is the one below.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

As you can see from the description it hooks into the wordpress query before the database is accessed to pre filter the listing before it is displayed on the page.

Is it that you are having issues getting the filter query itself to run ?

Please let me know.

Thanks,
Shane

#2100589

I tried finding a solution using this hook, but can't seem to get it to work. I will try to explain what I am doing because maybe there is a better solution.

Currently, I have a custom post-type company inside this post-type I have a repeating field 'Alternative business hours' this repeating fields contains a date and a text field (where the user can enter the alternative business hours). Now I am trying to create a view that show all the store that have alternative business hours this Sunday.

I really hope you can help me out.

#2101367

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Wessel,

So essentially you want to filter the view by the business days that they are open.

If a business is open on Sundays, then you want to display only those businesses when the user visits the page?

Please let me know if i'm understanding correctly.

Thanks,
Shane

#2101935

yes that's exactly what I am trying to accomplish.

I have tried using a filter on the date field in the reaping field, but this doesn't return any results. Even when there are openings time registered for that particular date.

#2102305

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Wessel,

Would you mind allowing me to have access to the site so that I can have a look at this for you ?

I doubt that it will be possible because you're essentially filtering a Parent by its child. While you're able to filter the child by the parent, the opposite doesn't hold true especially for repeating field groups.

However I will need to see your dataset to see if there are any possiblities.

Thanks,
Shane

#2103149

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Wessel,

Ok based on what I see it wont be able to work with the filter . I did a look at the possibilities by using the relationship filter but its not possible.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

The solution here might just be to mark the business themselves as open or closed or open using perhaps a checkbox and then filter based the post directly rather than doing it through the relationship.

Given that you have the custom fields for the days on the Business post type itself, you can simply write a hook to check that field and ensure that the respective field is not defined as closed based on the current day.

Lets say if you're currently on Tuesday, then you will check the tuesday field to ensure that it isn't equal to closed. If its not then you'll display that business.

Please let me know what you think of this.

Thanks,
Shane

#2103601

My issue is resolved now. Thank you!