Skip Navigation

[Resolved] Split: Split: Split: Setting up a view with mixed data between two relationships – copy custom fields to another post type post custom field – add total column – add session order

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
- 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 10 replies, has 2 voices.

Last updated by brettB-4 1 year, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2619519

I have another question on this now, but because you're already fully familiar with what I'm going for here, I'd like to continue working with you on this instead of leaving it to the random assignment of support team members on a new ticket. So can you split this again and I keep working with you?

The next thing needed is I have added the field back to the parent view you created to show the session. But I don't want it to appear as a first column <th> and <td> as I have set it up. I just set it up that way so you could see it. I'd like it to work to group the results by session the same way you helped set it up for us here:

hidden link

Only the Session should be a header here, not the Date, not the Round, not the Game. I tried to emulate how you already did this for us with another view, but what I tried didn't work. What I tried is as follows:

I added the following code above the start of the table in the View: show-all-teams view you created:

 
[heading condition="session" value="[types field='session'][/types]"]
<h5 style="background: #ffffff; color: #000000; padding: 7px; border-radius: 15px;">[types field='session'][/types]</h5>
[/heading]
 

I added and activated a custom code snippet called sorting-by-session-on-standings-by-round-page after duplicating the code you gave us called sorting-by-date-session-round-on-results-page. I duplicated that code and removed all the references to date, round and game headers in that, leaving just the session header and to use the Team session field (wpcf-session) instead of the Match session field (wpcf-session2). I changed the view ID line to

 $view_ids = array( 1353 ); 

as well so it would execute on the view we are working on here. I thought that might work, but it didn't change anything on the output.

I'm afraid I'm just not good enough at this. I'm doing my best to learn and trying to emulate things you've already done before I ask for more help. But it seems like I hit dead ends like this more often than not. I thought I might be able to get this step to work myself.

#2619643

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

When you copy the shortcode or filter, PHP language requires unique function name for the function you write for your shortcode or filter. So, when you copy the code, make sure you should also change the shortcode name and function name for shortcodes and with filter, make sure you should change the associated function name.

The code snippet you created, I've adjusted the code as given under for the code snippet namely "sorting-by-session-on-standings-by-round-page":
=> hidden link

add_filter('wpv_filter_query','func_sort_by_session_custom_field', 199, 3);
function func_sort_by_session_custom_field($query_args, $view_settings, $view_id ) {
  $view_ids = array( 1352 );
  if( in_array( $view_id, $view_ids)) {
    $query_args['meta_query'] = array(
        'relation' => 'AND',
        'session_clause' => array(
            'key' => 'wpcf-session',
            'compare' => 'EXISTS',
          
        ),
    );
    $query_args['orderby'] = array(
        'session_clause' => 'ASC',
    );
  }
  return $query_args;
}

And the parent view, I've adjusted the output as given under for the loop output section:
=> hidden link

<wpv-loop>
          <tr>
            	<td colspan="2">
                  	[heading condition="session" value="[types field='session'][/types]"]
<h5 style="background: #ffffff; color: #000000; padding: 7px; border-radius: 15px;">[types field='session'][/types]</h5>
[/heading]
           		 </td>
          </tr>
			<tr>
               <td>[wpv-post-link]</td>
               <td>[wpv-view name="standings-by-round-matches" teamid="[wpv-post-id]"]</td>
			</tr>
		</wpv-loop>


Can you please check now it works as expected:
- hidden link

I hope everything is resolved now and you are welcome to mark resolve this ticket as well and super happy to offer you the support as per your expectations. Have a nice time there.

#2619691

Is there any way to get the headers to appear above the tables similar to how we have it here:

hidden link

I see you have these headers within a <td> so they are part of the table and it is one table.
If we could get each session in its own table and then the session as a header above that table, this would be perfect. This does have everything we need to display here, so if it's too difficult to keep the look across these pages consistent with how this view is structured/built, I think we would be OK with this as is.

I tried adding your heading code above the <table> tag and that didn't work. It showed the background white section, but not the session name within that, and it only showed it once, not one for every session. I'm guessing it might not be doable with this being a view within a view. My logic skills with this just aren't at this level yet.

As for getting the grouping code to work, I'm glad to see I was close to getting it right and that I just didn't know that I had to change the function name in the two spots. Hopefully I'll get there.

#2619987

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Will this output work? hidden link

Otherwise, what we have to do is we have to print team name outside the table as header so output should look like:
- Session name
--- team name
--- round table with total

#2620103

This display approach is perfectly fine, but there is something wrong with the session grouping. On this page, Afternoon 3.0 is showing only 3 teams, SWAT (SW Atlanta) 3.0, Everlasting Lobstoppers, and We Don't Dink Alone. Bangers and Smash should also be in this session, but they are showing as the first team in the Afternoon 3.5 session.

You can see the correct session groupings here:

hidden link

All teams are in the correct session there.

I'm not sure what's causing that to be off on this view. It looks like once the first session was off the others followed suit the same way like the headers after the first one are just being displayed in the wrong spot.

Oh wait, one more thing. Is there any way to sort on the points in my calculated Total field to determine the order of team display within each session? That way the top point getting team in each session will display first and then down to the lowest.

Once this is done for the Men's Doubles results, my next step is to add the same standings for Women's Doubles, Mixed Doubles A and Mixed Doubles B. That should be a simple matter of copying and pasting ALL of the existing code in the view and just changing the field names for each set of standings. I'd think I'll be able to do that part successfully. The page will be huge at that point, so I may try to add a session filter, or maybe a filter to show Men's Doubles, Women's Doubles, Mixed Doubles A, and Mixed Doubles B separately. I'll see how it looks when it's done before I decide what to do there.

#2620223

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It was really complex as it was involved custom JS code to filter the rows based on the total score of rounds.

Can you please check now: hidden link

we have call the view as given under:
=> hidden link

<h3>Morning - 3.0</h3>
[wpv-view name="show-all-teams" session="Morning - 3.0" sessionslug="morning30"]
<h3>Morning - 3.5</h3>
[wpv-view name="show-all-teams" session="Morning - 3.5" sessionslug="morning35"]
<h3>Morning - 4.0+</h3>
[wpv-view name="show-all-teams" session="Morning - 4.0+" sessionslug="morning40plus"]
<h3>Afternoon - 3.0</h3>
[wpv-view name="show-all-teams" session="Afternoon - 3.0" sessionslug="afternoon30"]
<h3>Afternoon - 3.5</h3>
[wpv-view name="show-all-teams" session="Afternoon - 3.5" sessionslug="afternoon35"]
<h3>Afternoon - 4.0+</h3>
[wpv-view name="show-all-teams" session="Afternoon - 4.0+" sessionslug="afternoon40plus"]

With the following view we added the following query filter to the "Query filter" section:
=> hidden link

Custom field filter
Select items with field:
Session is a string equal to VIEW_PARAM(session)

And the loop output is configured as given under:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
<table id="[wpv-attribute name='sessionslug']" class="customtable tablesorter" sessionname="[wpv-attribute name='sessionslug']" width="100%">
		<tbody class="wpv-loop js-wpv-loop">
            <tr>
              <th>Team</th>
              <th  class="cr1">R1</th>
              <th  class="cr2">R2</th>
              <th  class="cr3">R3</th>
              <th  class="cr4">R4</th>
              <th  class="cr5">R5</th>
             
           </tr>
         
	<wpv-loop>
         <tbody class="wpv-loop js-wpv-loop">
           <tr class="customrow">
             	<td>[wpv-post-link]</td>
             	[wpv-view name="standings-by-round-matches" teamid="[wpv-post-id]"]
             	
           </tr>
		</wpv-loop>
		</tbody>
	</table>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Also, I've added the following custom JS code to JS editor of the view ID: 1352

jQuery(document).ready(function($){
  
  $("table.customtable").each(function(indexval, objval) {
  
  currenttable = $(this);
  firstrow = $(this).find("tr:first");
  totalround = $(this).find("tr:first th").length-1;
  $(firstrow).append('<th style="background: #02fd14; color: #000000; font-weight: bold;">TOTAL</th>');
 	$(this).find('tr.customrow').each(function(i) {
     
      tdtotal=0;
      
      tdavailable =$(this).find('td.customtd').length;
      difference = totalround - tdavailable;
      
      console.log("difference=="+difference);
     
      if(difference==2){
      	$(currenttable).find("tr:first").find("th.cr4").hide();
        $(currenttable).find("tr:first").find("th.cr5").hide();
      }
      
      $(this).find('td.customtd').each(function(j) {
        
        if($(this).text() != '') {
      		tdtotal = tdtotal + parseInt($(this).text());
        }  
       // console.log($(this).text())
        
    });
      $(this).append('<td>'+tdtotal+'</td>');
     //$(this).find("td:last").text(tdtotal);
      });
  
 
  
  var table, rows, switching, i, x, y, shouldSwitch;
  table = document.getElementById($(this).attr('id'));
  switching = true;
  /*Make a loop that will continue until
  no switching has been done:*/
  while (switching) {
    //start by saying: no switching is done:
    switching = false;
    rows = table.rows;
    
    targettd = totalround-difference;
    /*Loop through all table rows (except the
    first, which contains table headers):*/
    for (i = 1; i < (rows.length-1); i++) {
      //start by saying there should be no switching:
      shouldSwitch = false;
      /*Get the two elements you want to compare,
      one from current row and one from the next:*/
      x = rows[i].getElementsByTagName("TD")[targettd];
      y = rows[i + 1].getElementsByTagName("TD")[targettd];
       if (Number(x.innerHTML) < Number(y.innerHTML)) {
        //if so, mark as a switch and break the loop:
        shouldSwitch = true;
        break;
      }
    }
    if (shouldSwitch) {
      /*If a switch has been marked, make the switch
      and mark that a switch has been done:*/
      rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
      switching = true;
    }
  }

});
    
});

The child view that shows the matches content is configured as you can see:
=> hidden link

Can you please confirm now, it works as expected.

#2620237

Holy moly! I'm so sorry this was that difficult. Thanks SO MUCH for being willing to set this up.

This is now PERFECT except for one comparatively minor thing. The total point sorting is only working on the afternoon sessions.

I'll wait until you determine the cause there and then I'll proceed to set up everything for Women's Doubles, Mixed Doubles A, and Mixed Doubles B. I will do everything I can to do that on my own. I know that doing that will force me to get more familiar with, and to a better level of understanding of, everything you've set up here. After that is done, I'll have EVERYTHING we were hoping to achieve with the Inaugural Tournament results. I'm thinking I may have to set up separate views for Men's, Women's, Mixed A, and Mixed B where I duplicate everything you've done and just change the fields instead of trying to add all those fields to this view. I'll see how that goes when I try it.

Then the final step in this full process for me will be adding taxonomy based front-end filters to all these pages with Views that we have set up to make it to where that filter will determine which tournament/league data is shown. I hope everything will keep working through that, but I fear that any structural changes to how the tournaments are set up will pose major problems. As long as the tournaments use the identical structure, I'm thinking this should keep working through the use of the taxonomy filter. We'll have teams, matches and results from another tournament soon. As such, I may have to scrap the idea of having a taxonomy filter determine the tournament/league results shown. I may have to set up fully separate views for each tournament/league and adjust your code as needed to meet the structure of each one. I'll cross that bridge when I get there. If I can get this to where I can make it all work without having to rely so heavily on your help, then we'll be where we need to be. If it all turns out to where I can't do this at all without substantial help from you as is happening here, I won't impose on you for that. I'm just highly grateful for everything you guys have done here to push the limits of what can be done with this.

Thanks IMMENSELY for all this help.

#2620247

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've adjusted the code added to your view's JS box as given under:
=> hidden link

jQuery(document).ready(function($){
  
  $("table.customtable").each(function(indexval, objval) {
  var targettd=0;
  currenttable = $(this);
  firstrow = $(this).find("tr:first");
  totalround = $(this).find("tr:first th").length-1;
  $(firstrow).append('<th style="background: #02fd14; color: #000000; font-weight: bold;">TOTAL</th>');
 	$(this).find('tr.customrow').each(function(i) {
     
      tdtotal=0;
      
      tdavailable =$(this).find('td.customtd').length;
      difference = totalround - tdavailable;
      
      console.log("difference=="+difference);
     
      if(difference==0){
        targettd=tdavailable+1;
      }else if(difference==2){
      	$(currenttable).find("tr:first").find("th.cr4").hide();
        $(currenttable).find("tr:first").find("th.cr5").hide();
        targettd=tdavailable+1;
      }
      
      $(this).find('td.customtd').each(function(j) {
        
        if($(this).text() != '') {
      		tdtotal = tdtotal + parseInt($(this).text());
        }  
       // console.log($(this).text())
        
    });
      $(this).append('<td>'+tdtotal+'</td>');
     //$(this).find("td:last").text(tdtotal);
      });
  
 
  
  var table, rows, switching, i, x, y, shouldSwitch;
  table = document.getElementById($(this).attr('id'));
  switching = true;
  /*Make a loop that will continue until
  no switching has been done:*/
  while (switching) {
    //start by saying: no switching is done:
    switching = false;
    rows = table.rows;
    
    //targettd = totalround-difference;
    /*Loop through all table rows (except the
    first, which contains table headers):*/
    for (i = 1; i < (rows.length-1); i++) {
      //start by saying there should be no switching:
      shouldSwitch = false;
      /*Get the two elements you want to compare,
      one from current row and one from the next:*/
      x = rows[i].getElementsByTagName("TD")[targettd];
      y = rows[i + 1].getElementsByTagName("TD")[targettd];
       if (Number(x.innerHTML) < Number(y.innerHTML)) {
        //if so, mark as a switch and break the loop:
        shouldSwitch = true;
        break;
      }
    }
    if (shouldSwitch) {
      /*If a switch has been marked, make the switch
      and mark that a switch has been done:*/
      rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
      switching = true;
    }
  }

});
  

  
});

I can see its working as expected now: hidden link

Glad to help and have a great weekend.

#2620439

You have an awesome weekend too. This is now perfect, so I'll be able to mark this one resolved now.

So now moving to the next question / ticket split, I am going to set this up for showing Women's Doubles, Mixed Doubles A, and Mixed Doubles B in addition to the Men's Doubles only that we have here. I'm looking over how everything is done here and this is my resulting question.

Within the show-all-teams view here:

hidden link

After looking over your code fully, and seeing how the loops are set up to display the table rows within a single table, I'm thinking the easiest way to show Men's Doubles, Women's Doubles, Mixed Doubles A and Mixed Doubles B in separate tables under the same session groupings is as follows:

I want to take your line of code here:

             	[wpv-view name="standings-by-round-matches" teamid="[wpv-post-id]"]

and set it up for conditional display. I would like to have a query filter at the top of the page that end users control. That filter would just be a dropdown select box that has Men's Doubles, Women's Doubles, Mixed Doubles A and Mixed Doubles B as the selection options. Then what I would do with your line above would be to change it as follows:

             	[wpv-conditional if="('?' eq 'Men's Doubles')"] [wpv-view name="standings-by-round-matches-men" teamid="[wpv-post-id]"][/wpv-conditional] 
             	[wpv-conditional if="('?' eq 'Women's Doubles')"] [wpv-view name="standings-by-round-matches-women" teamid="[wpv-post-id]"][/wpv-conditional]
             	[wpv-conditional if="('?' eq 'Mixed Doubles A')"] [wpv-view name="standings-by-round-matches-mixed-a" teamid="[wpv-post-id]"][/wpv-conditional]
             	[wpv-conditional if="('?' eq 'Mixed Doubles B')"] [wpv-view name="standings-by-round-matches-mixed-b" teamid="[wpv-post-id]"][/wpv-conditional]

Note that where I have inserted the ? characters above, that just means I'm unsure of what would need to be inserted there.

My problem with setting this up myself is I am unsure about how to set up this filter. I do not have a field or taxonomy for Men's Doubles, Women's Doubles, MIxed Doubles A, and Mixed Doubles B. There's no way to have this as a field or taxonomy because all of these scores are within the Matches content type, not separated as their own content type. So I wouldn't have a way to define this query filter in a way where I know how to do it. Is there any way to just set up a basic select drop-down where we provide the options without running it through any field or taxonomy and have the results from that work within the conditional provided my ? characters are replaced with how this really needs to be done?

Then once the front-end query filter is set up, I will also duplicate/rename your current standings-by-round-matches views as needed to have separate views for standings-by-round-matches-men standings-by-round-matches-women standings-by-round-matches-mixed-a and standings-by-round-matches-mixed-b. I should be able to do this step myself, unless you think I'll get some unexpected surprises stemming from the javascript code you added trying to do this.

I have gone ahead and duplicated all the views and changed all the fields as needed. I kept your original standing-by-round-matches view as is just in case I'm wrong about this being the best approach. So all I should need help on here is the above question about setting up the filter.

#2620753

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've split the ticket and we can continue with the following split ticket:
- https://toolset.com/forums/topic/split-setting-up-a-view-with-mixed-data-between-two-relationships-copy-custom-fields-to-another-post-type-post-custom-field-session-wise-display-for-other-entities/

You are welcome to mark resolve this ticket. Really glad to help you out with this really complex setup.

#2620989

My issue is resolved now. Thank you!