Skip Navigation

[Resolved] View to provide counts of the number of times a field has specific values

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 – 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)

Author
Posts
#2524445

I actually followed everything you said. My head was exploding again while reading it all, but I do understand everything you said. I don't think I'd have ever been able to do this myself though. Like you said, lots of real-world scenario learning would be required to know all of this stuff at this level. I'm getting *some* of that through all these features your team has helped me on with the four different sites I've worked on so far with Toolset. While I have gotten to where I can *emulate* some of the things you've showed me on one site for other uses on another site, I haven't gotten to where I know it enough to come up with a solution like this for a new situation. I think it would take many years of daily use for me to learn the system well enough to come up with this solution you've provided here.

THANKS SO MUCH (increase font size here to 100 points) - 😉 Also thanks hugely for the detailed explanation in hopes of getting me to understand what's done and how to do it. I think I fully understand everything, but I'd have great difficulty with doing anything other than a nearly direct emulation of this functionality if needed in some other form on another site, just copying what you've done and tweaking it. If anything needs modification beyond just changing field names or other easy things like that, this would very likely be beyond me to succeed with.

The reason the query filters were set to display Constant values and were empty was because I had no clue what I needed to enter here. That was my stumbling point in trying to follow your instructions from the previous post. Even after seeing what you entered, I know there is no way I'd have ever come up with that.

I'm amazed that this ended up being such an extremely complex request/solution.

I laughed out loud when you said "The next step is a little trickier". I was marveling at how tricky the previous step was. I was following everything you were saying a bit like a waterskier that has fallen down into the water keeps following the boat as long as they keep holding onto the toe-rope and then you said it was going to be trickier. I laughed and said "Oh no, how am I going to follow this one?". But I at least understand everything you said you did.

Let me add some more test Rides to the system to test that the counts are all correct. It looks like it's working fine now, but I'll beat it up with some more test Rides to make sure. I'll play around with the display on the parent view some too. I think I'll try to add a conditional to not display any ride leaders with a zero ride count and I'll try to set the sort to be on the Ride Count so the ones with the most rides will be at the top. I'm hoping I'll at least be able to handle those things myself. I'll let you know if I have any problems there or see anything else that needs to be addressed, but I think this is doing what's needed now.

Whew.

#2524757

I'm so glad that Toolset plugins and the support team have been proven useful for these projects.
( and that we also managed to make you laugh out loud in the process 🙂 )

Feel free to continue testing this setup and let me know if you have any follow-up questions.

For a new question or concern, you're welcome to start a new ticket.

#2525273

Argh. I'm finding that I have to ask for your assistance setting up the conditional to eliminate the display of Riders that have not led any rides. I thought this would be something simple that I could handle, but it seems like nothing is working out to be simple.

I tried the following in the Ride Leader Number of Rides View:

<wpv-loop>
[wpv-conditional if="( '[wpv-view name="ride-leader-number-of-rides-list-count-field" targetrider="[wpv-post-id]"]' ne '0' )"]
<tr>
[wpv-post-body view_template="loop-item-in-ride-leader-number-of-rides-list"]
</tr>
[/wpv-conditional]
</wpv-loop>

But it looks like there's a problem with the syntax in the conditional line due to the use of the targetrider bit. I wasn't sure how to set that up. What I did caused the page to not load and it gave a 504 - Gateway Timeout error.

I tried setting up the same conditional wrapping the two <td> items within the loop item and that produced the same results.

So I just don't know the syntax to set up the conditional based on this count field not being empty.

#2525275

And, I'm also seeing that I have no idea how to set up the view to sort on this count field either. I currently have it set up to sort alphabetically and ascending on the post title. I'd prefer to have it sort on the count field with a descending sort so the riders with the most rides led will be at the top going down to the riders with the least, but not displaying ones with no rides led as I tried to do in the post above.

But this custom field you've created is not among the possibilities in the sort options and I don't know how to set up sorting outside of this interface. Man, I'm feeling too helpless here.

I hope these final two requests do not prove to be as surprisingly complicated as the previous setup. I thought I'd be able to do these last two things myself, but the nature of this count field displayed through a separate view has me stumped.

#2527745

Instead of using a conditional statement, here is a better alternative to hiding the rows for the riders who haven't led any rides.

1. In the view "Ride Leader Number of Rides List", I added a unique ID to each table row, based on the rider post's ID, so that each one can be targeted individually using the CSS code:
( screenshot: hidden link )


<tr id="rider-[wpv-post-id]">

2. In the child view "Ride Leader Number of Rides List Count Field", I included the following CSS code, that hides the table row, only if it doesn't return any results.
( screenshot: hidden link )


<style type="text/css"> tr#rider-[wpv-attribute name="targetrider"] {display:none;} </style>

Notes:
a). The CSS code is added within the "wpv-no-items-found" tags, which is why it is only included for the child view's loop when it doesn't return any result.

b). The CSS code uses the shortcode "wpv-attribute" to get the ID of the rider post that is being passed by the parent view through the shortcode attribute "targetrider".
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-attribute

As for sorting the results by the number of rides led, it is not possible through the parent view's sorting/ordering settings or query, because the number of rides is calculated by the child view and not the parent view.

To achieve this, you'll need to use some custom script, that orders/sorts the table on the front end, once it has been generated.

Here are some of the example scripts that you can use:
hidden link
hidden link

You'll find some useful pointers on this topic in this other support forum thread:
https://toolset.com/forums/topic/sorting-nested-tables/page/2/

For more personalized assistance around custom code/scripts, you can hire a professional from our list of recommended contractors:
https://toolset.com/contractors/

#2527833

Wow. Again, mind blown as to how much more difficult/complex this was/is compared to what I was expecting to find when I tried it. At least I don't feel as bad about my failure.

Eliminating all the ones with no results is very good. I see that is working. Thanks hugely again for that.

After I made my reply asking about sorting on the number of rides, I thought about it more and was going to ask about having both columns of the table being sortable because I could see occasions where our admin would want it sorted both ways. I tried setting it that way from the Loop Wizard to get it to where the ride count field would be sortable that way, but I saw that it wasn't working.

That makes sense that it can't sort on it because the count comes from the other view.

I'll study the examples of how to get that done that you provided, but I can tell it is likely that we'd need to go to hiring a contractor for this. We're doing that this morning for three of the pending functionality support ticket issues we had for one of the other Toolset powered websites I'm working on. We have a Zoom meeting scheduled with one of those contractors that I sought out from your list. So I'll see how he does with those three problems and then I'll ask him about this.

Thanks so much again for getting it this far. Definitely more than I could have hoped for given the complexity it turned out to require. I had no idea this would be this involved when I initially posted this ticket. I also have no idea how you guys are willing to provide this much help with using Toolset, but I'm telling every client I have that Toolset is the biggest bargain there is for plugins because of your support team. You should have more happy customers coming from my base of clients soon.

#2530123

Thank you so much for your kind words and support. It means a lot to us.

I'm glad that I was able to assist you in laying the foundation for the basic data structure. I'm also confident that an experienced contractor will be able to help with any remaining customization work.

You're welcome to mark this ticket as resolved and start a new one, for each new question or concern - we're here to help!