Skip Navigation

[Resolved] filter on values specific to the current record within the loop

This support ticket is created 5 years, 9 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 5 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1215351

I need some help setting up a filtered view - I have tried and failed - most views on our new web site are working - this one is problematic as it need

for each event we need to filter on values specific to the event

So ...

places_sold_for_this event = maximum_places_for_this event - places_available_for_this event;

if (places_sold_for_this event => minimum_places_for_this event) {
// Costs are covered

if (places_available_for_this event > 0) {
// But we have some residual places remaining

if (startDate_for_this event > Today && startDate_for_this event > Three_months_from_now) {
// The event starts beyond today, but within three months

// Show the event with a 10% discount
}

}

}

Example page at hidden link

I cannot work out the filter for doing this - mainly because a number of the variables are dependent upon the current record in the loop

Or are filters the wrong way to approach this - and I should be using conditionals - that I also tried - but failed on that score miserably

#1216627

Hi, I'm having trouble understanding the logic here. Is this the only result that should be displayed in your View? If not, please provide some more information about the nested "if"s.

// Show the event with a 10% discount

Conditionals can be very useful if pagination is not required. If pagination is required in the View, conditionals can cause some minor problems. For example if you want to show 10 results per page, but a conditional hides 2 of those results, your View will only show 8 results on the page. In the next page of results, it may only show 3...so it looks inconsistent from page to page.

To filter on values based on the current element in the loop, you could use shortcode attributes and nested Views. This technique is called passing arguments to Views.
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#1216808

All three of the IFs have to be met - then event information is output to the page - yes - pagination is not required

So the logic is have I sold more than the minimum number of places for this event AND are there some places remaining available AND is the event starting within three months of today - then display the event - ELSE this event is not displayed

#1217130
Screen Shot 2019-03-19 at 12.17.18 PM.png

Okay thanks, I understand more clearly now. I think you'll need a combination of Query Filters and conditional HTML.

if (places_sold_for_this event => minimum_places_for_this event) {

I don't know of an easy way to filter a View by comparing two custom field values like this, so I think this part is best accomplished as a conditional statement in the Loop of your View.

if (places_available_for_this event > 0) {

This part can be handled easily with a Query Filter testing this custom field value as an UNSIGNED value greater than Constant 0.

if (startDate_for_this event > Today && startDate_for_this event > Three_months_from_now) {

This part is best handled as a Query Filter. Add a filter on this start date field as an UNSIGNED value between Constant FUTURE_DAY(1) and FUTURE_MONTH(3). I'm attaching an example here.

So all together that's two Query Filters and one conditional statement. You should be able to build the conditional directly in the loop of your View using the conditional HTML builder. Let me know if you have questions about that.

#1217541

Well that certainly taught me a lot about toolset - I think it now works

hidden link

There's a real mix of conditionals and filters in there - but it pretty much displays the right records now

Now I just need to get the 10% discount shown and the specific booking form

But those are easy now I am showing the correct records

#1218401

OK that's great news. Feel free to set up separate tickets if you need additional assistance with those forms and discount displays.