Skip Navigation

[Resolved] 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

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

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

Assisted by: Minesh.

Author
Posts
#2618943

OK, I tried that and it didn't work either. The code I added to the loop to create this Total column is as follows:

<td>[wpv-calculate][wpv-conditional if="( $(wpcf-round) eq 'Round 1' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional]+[wpv-conditional if="( $(wpcf-round) eq 'Round 2' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional][/wpv-calculate]+[wpv-conditional if="( $(wpcf-round) eq 'Round 3' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional]+[wpv-conditional if="( $(wpcf-round) eq 'Round 4' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional]+[wpv-conditional if="( $(wpcf-round) eq 'Round 5' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional][/wpv-calculate]</td>

I just copied and pasted all the conditional code you set up to get the correct score for each team in each round and added + between them to do the calculation. I also removed all the spacing/line breaks because I feared that would interfere with the calculation functionality in some way. So I have all of this as one continual line. I'm sure there's a syntax problem in there somewhere. The result of adding this code causes the view output to completely white screen. Nothing shows on the page with this added, not even the stuff you had working before. So I removed this code on the view right now. I'll see what you have to say about this before trying to add anything different.

Here is the code snippet provided to us in another support thread for doing the calculations:

<?php
/**
* New custom code snippet (replace this with snippet description).
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts,$content=null) {
$content = wpv_do_shortcode($content);
$content = eval("return $content;");
return round($content);
}

This code works perfectly with the calculations we've already set up. I'm guessing something with all the conditionals present in my attempt above is causing this to fail.

#2619379

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

We have to use the custom javascript solution to calculate the total as well as to add the Total column as well as to remove the empty round columns.

I've added the following code to your view's "Loop Editor" section's JS editor:
=> hidden link

jQuery(document).ready(function($){
 
  jQuery('table.customtable').each(function(a, tbl) {
    var currentTableRows = $('table.customtable').find("tr").length - 1;
    var tdtotal = 0;
    $(tbl).find('th.cround').each(function(i) {
       
        var currentTable = $(tbl);
    	var tds = currentTable.find('tr td:nth-child(' + (i + 1) + ')');
       	
      	if(tds.text() != '') {
      		tdtotal = tdtotal + parseInt(tds.text());
        }  
      
        if(tds.length ==0){
           $(this).hide();
        }       
       
    });
    firstrow = $(tbl).find("tr:first");
 
    $(firstrow).append('<th style="background: #02fd14; color: #000000; font-weight: bold;">TOTAL</th>');
    $($(tbl).find("tr:eq(1)")).append('<td>'+tdtotal+'</td>');
  
});
 
});

Can you please confirm it works as expected: hidden link

#2619391

Wow! Yeah, it's looking perfect for showing the totals and trimming the output to match the number of rounds. You guys are awesome.

Let me double-check all the math done on all of these before I mark this one as resolved, but this looks awesome on first glance.

#2619397

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.

#2619521

Minesh
Supporter

Languages: English (English )

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

As I shared with previous ticket as well, we entertain only one question per ticket. This will help other users searching on the forum as well a help us to write correct problem resolution summery.

I've split the ticket with your new question and I urge you to mark resolve all tickets including this one.

We will continue with the split ticket with your new question with the following ticket:
=> https://toolset.com/forums/topic/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/

#2619623

I'll mark this one resolved as soon as I have time to check the math is working perfectly here. Thanks. Should be very soon.

#2619653

Minesh
Supporter

Languages: English (English )

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

ok fine - it should be resolved now.

#2619703

My issue is resolved now. Thank you! Another very hard one, but again, awesome support.

The math worked perfectly. I did encounter a major problem with having 3 teams with similar/same names where I didn't have them assigned to the correct matches. I had to sort all of that out but corrected everything and the math is perfect. So this one is done. Thanks as always.