Home › Toolset Professional Support › [Resolved] Split: Split: Grouping View results by a field.-add custom search for ride contact field – registration ride leader
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.
This topic is split from https://toolset.com/forums/topic/split-grouping-view-results-by-a-field-add-custom-search-for-ride-contact-field/
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10: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/Kolkata (GMT+05:30)
This topic contains 22 replies, has 2 voices.
Last updated by lesleeM 1 year, 4 months ago.
Assisted by: Minesh.
OK, I've decided to just use Ride Leader as the filter. That is working. I removed the filter where I was trying to use Ride Contact. I'll consider that part of this resolved, so if we need to split the ticket again, that's no problem. The biggest thing left to address is
3) The parent view is showing the Ride Leader name as a header for EVERY ride and then it will show the registrations for that specific ride under the header corresponding to that Ride. Instead, I only want the Ride Leader field to display as a header once, and then the single table below that should show all Registrations for all Rides. There shouldn't be a separate table showing Registrations for every Ride. All of them should be combined into one table.
Is there any way to do this?
Hello. Thank you for contacting the Toolset support.
To your parent view to group the results, I've added the following code to the "Custom Code" section offered by Toolset with the code snippet namely "groupbycontactname":
=> => hidden link
add_shortcode('heading', 'func_custom_groupby_contactname'); function func_custom_groupby_contactname($atts, $content = '') { static $cname= null; $condition = $atts['condition'];; $value = $atts['value'];; switch ($condition) { case 'cname': if ($$condition != $value) { $$condition = $value; return wpv_do_shortcode($content); } break; } return ''; }
And call the above shortcode inside your parent view's loop as given under:
[heading condition="cname" value="[types field='ride-contact-2'][/types]"] <h3>[types field="ride-contact-2"][/types]</h3> [/heading]
Can you please confirm it works as expected now:
=> hidden link
Yep, this is exactly what was needed for the grouping under one header. Thanks. Seeing that you did it the same way as what I was trying to emulate from where you helped us with this previously has me frustrated more by my failure. I'm going to have to study what you did here that I missed when I tried it.
Now I'm seeing it is down to two things left before this is perfect. Feel free to split this ticket again each time.
The next issue is scroll down to the Kenny Moore header. See how there are three different tables there? That's because those Registrations are coming from three different Rides. Is there any way to combine those results to have them show as only one table? We're trying to get everyone that has ever Registered for any Ride led by each Ride Leader to appear as a single results table. We're going to try to build some form of YOUR RIDERS functionality for each Ride Leader and this is the start of that.
Its not possible to merge the table's as you know its nested view and with every item we are calling the child view that holds the table. As you already understand the every table created is for specific entry child posts.
What if we don't display the output as a table? What if we just have an unformatted list? How would that show the output as it comes from multiple Rides? Would it just add the next one right under the previous one? If so, that would work. Really we don't even need the name field for the people that registered for the functionality needed here. We really only need the e-mail addresses for what I'm thinking of doing. If we can get them to list one per line under the Ride Leader header, that would work. But we'd just need a way to weed out duplicates. There will be duplicates as most Rides will have a regular group that comes out frequently.
I've modified the child view and removed the table:
=> hidden link
This is how it looks like:
- hidden link
Yeah, this is perfectly fine like this. Thanks. So that part of this is done.
The next question is if there is a way to eliminate the duplicates within the View results. The check for that should be on the e-mail address field. You can see two entries for Todd Green under the Kenny Moore header. As we get our members introduced to and more used to using the Registration system, I expect that there will be MANY duplicates in here as we have several rides that happen on a weekly basis.
Note that I made this view one that hides the results until a filter is applied. So you'll have to select Kenny Moore on the filter to see what I'm talking about on this now. If we can just eliminate the duplicates this will be perfect.
Feel free to split this one more time for that question.
When I select the "Kenny Moore" - I see the following page:
=> hidden link
Do you mean you do not want to display the last result (the name with kenny) even though the email is different?
No, the ones with the name Kenny are fine as is. I'm talking about the two entries for Todd Green. We want to eliminate showing a result when the e-mail address is the same as any other result. The e-mail address has to be unique.
Note that if Toolset does not have this capability built in yet, consider this a feature request as well for you to match capabilities with Drupal's views system. They have settings to keep results distinct. I'm not 100% sure if they have it where that distinction can be set at the single field level like I'm asking for here on the e-mail address field, but I *think* they do. It's been awhile since I've used it for this sort of thing, so my memory is fuzzy on that detail. I *know* they have the ability to eliminate duplicates in some way.
Can you please share admin access details as the previous admin access details you shared is not working at this end.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I've added the following code to "Custom Code" section offered by Toolset with the code snippet namely "groupbycontactname":
=> hidden link
add_filter( 'wpv_filter_query_post_process', 'func_remove_duplicate_ride_email', 10, 3 ); function func_remove_duplicate_ride_email( $query, $view_settings, $view_id ) { if ($view_id==7992 and !empty( $query->posts ) ) { $all_posts = $query->posts; static $duplicate_email= array(); foreach($query->posts as $k=>$v): $current_email = get_post_meta($v->ID,'wpcf-email',true); if(in_array($current_email,$duplicate_email)){ $duplicate_index[] =$k; } $duplicate_email[] = get_post_meta($v->ID,'wpcf-email',true); endforeach; if(!empty($duplicate_index)){ foreach($duplicate_index as $k=>$v): unset($all_posts[$v]); endforeach; } $query->posts = $all_posts; $query->found_posts = count($all_posts); // modify the count of found posts $query->post_count = count($all_posts); // modify the count of displayed posts } return $query; }
More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process
Can you please confirm it works as expected now and it removed the duplicate entries from the page:
=> hidden link
Looks perfect. Thanks a bunch!
See if you can add something like that as a selectable option in setting up views in some way. I think that would be a good tool to have that many would get use from in setting up various views. Have a checkbox somewhere in the views setup saying "Remove duplicate view results" or "Make view results distinct" or something like that.
My issue is resolved now. Thank you!
Re-opening this ticket now. Sorry about this, but I tried to duplicate what you have done here to apply it to another view I set up and it isn't working.
The new view is here:
hidden link
I duplicated your code snippet and added a new one called remove-duplicates-from-my-riders-view . I changed the function name and the view ID # on that, but the duplicate Todd Green entry is still appearing on this one. You can see that on this page:
hidden link
I decided I wanted to take what you set up for us showing ALL registrations for ALL Ride Leaders and also provide this information for registrations specific to each Ride Leader on their Ride Leader page. But the duplicates are still showing on this view's results.
When you mark the ticket as resolved the private access details you shared is automatically deleted.
Can you please send me admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.