Skip Navigation

[Resolved] Filters on view no working

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 3 voices.

Last updated by Waqar 6 months, 2 weeks ago.

Assisted by: Waqar.

Author
Posts
#2695009
unhide-table.png
unhidden-BE_Storage.png

I am trying to:

I have a view that returns entries for two post types, both post types have a field for "archiving" their posts. The view should not return posts that are archived, but they are still present in the view. The view in question is called 'Per Warehouse Inventory View P4' and has an id of 1385.

The fields in question are 'wpcf-container-archived' and 'wpcf-shipment-archived'. They are drop downs with '1' = yes, and '2' = No. The filters applied in the view are for those fields as number 'that is different' from 1.

Link to a page where the issue can be seen:

hidden link (from the menu it's under Reporting => Per Warehouse)

Note this view is hidden on the page, and is loaded on the page via a different view. You can see it by inspecting and removing the class of 'hide' from any of the entries where the table id starts with 'totalsdata'. I will upload a screenshot so you can see this clearly.

I expected to see:

The hidden tables should not contain any containers or shipments that are archived, I've tested with several shipments and containers, but here are two values that you can clearly see shouldn't be in there but are. Note these are both located in the BE Storage table which has an ide of 'totalsdata1267'.

container name = TRHU4836488
shipment name = 104488

Instead, I got:

It looks like I'm getting all results regardless of the archive field being set to yes (1) or not. But the other two filters appear to be working. Can you please take a look into this and let me know what can be done to get these filters working.

Thanks!

#2695043

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

As the setup sounds somewhat complex, with the View included being loaded on the page via another View, could I ask you to please create a test page with a new simplified View which outputs the post types in question—I suggest you just output the post title, and then the value of these archived custom fields—and includes the Query Filters relating to these archived custom fields.

There we should be able to see in a cleaner set up what the View outputs, and quickly identify examples where it is outputting the wrong posts, so that we can look into why.

Thanks.

#2695068

Hey Nigel,

Thanks for the response, I've done as you asked and created/shared a new backup of the site. There is now a new view for testing, and a new page for you to view it on. I had to remove the parent filter for the view to return anything, but that shouldn't hinder anything from what I can see.

New View: Per Warehouse Filter Test (ID 6318)
New Page: page_id=6315

I may know why this is happening, but will still need some help fixing it. There is custom code running that allows us to use OR instead of AND, the snippet is called "query-with-or'.

The disired outcome here is to return containers with a status of 2, and Not archived, AND Shipments with a quantity greater than 0 AND Not archived (not archived is the number different from 1 filter).

Appreciate any help you can provide.

Thanks,
Matt

#2695119

Hi Matt,

Thank you for sharing these details.

The challenge with this query is that with "OR" operator for the custom fields filter, a result becomes eligible to show if any one of the conditions becomes true. Whereas for your requirement, you need a combination of 'AND' and "OR".
( since there are two different levels/fields criteria of filtering for each post type )

I'd recommend removing the custom field filtering for the archive fields (i.e. 'Shipment Archived' and 'Container Archived'), from the view's query filter and keeping filters for the other two fields ( i.e. 'Container Status' and 'Shipment Quantity' ).

This will give you the filtered list based on half the criteria, from the view's query. For the other half (i.e. archived status), you can use conditional check in the view's 'Loop Editor'.

Where you have:


<tr>
	[wpv-post-body view_template="loop-item-in-per-warehouse-filter-test"]
</tr>

You'll replace it with:


[wpv-conditional if="( $(wpcf-container-archived) ne '1' ) AND ( '[wpv-post-type show="single"]' eq 'Container' )"]
<tr>
	[wpv-post-body view_template="loop-item-in-per-warehouse-filter-test"]
</tr>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-shipment-archived) ne '1' ) AND ( '[wpv-post-type show="single"]' eq 'Shipments' )"]
<tr>
	[wpv-post-body view_template="loop-item-in-per-warehouse-filter-test"]
</tr>
[/wpv-conditional]

The conditional blocks will make sure that the row of a result coming from the query is only shown if the relevant post type result is not archived, based on its respective custom field value.

Related documentation:
https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2695160

thanks Waqar, that worked as intended!