Skip Navigation

[Resolved] Display Data in a table from multiple post types

This support ticket is created 4 years, 11 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 40 replies, has 3 voices.

Last updated by Christian Cox 4 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1476875

Yes, the ranking should be based on player performance.
1. Is there a custom field type for time? as the player performance field is currently set as single line field type as I want to input time as HH:MM:SS.
2. I have been able to replicate the single event view as in your example but what I actually want to display is a filterable view for all events. I want to set filters such users can filter by the following
a. Country
b. Gender
c. Age Group
d. Event

#1479647

1. Is there a custom field type for time? as the player performance field is currently set as single line field type as I want to input time as HH:MM:SS.
Types has a custom date field that allows you to enter a time and pick a date on a calendar, but there is no time-only field. You would probably use some type of text field to hold this information, like a single line field.

Yes, the ranking should be based on player performance.
Okay so we need to rethink the structure of the data a bit. The main problem here is Views is set up to allow you to sort and filter by custom fields and post relationships, however it is not currently possible to filter by custom fields from more than one post type. In other words, you can filter by custom fields in the Player post, and also filter by Event post relationship, but you cannot also filter by custom fields from the Event post in this same View. That's a limitation of Views that we need to consider when structuring this table and filter setup. So since Player Performance dictates the sort order of the table, and Player Performance is calculated per Event, then we are limited to sorting and filtering using custom fields in the same post type as the Player Performance field. Right now that field is in the intermediary post type.

This complicates things a bit, and it's why I wanted to set up a test site so you can see how things must be organized in a practical setup. I have made an adjustment so that you can now see the intermediary post type in wp-admin. This will allow us to modify the View a bit to support the filters and sorting we need. I duplicated the Players in this Event View so we can create a similar View for Players with Event filters. I have set the new View's Content Selection to include only the intermediary post type. I have deleted the post relationship filter related to the post where the View is shown, and moved the View into the page you created here: hidden link

The new View is here: hidden link
I've added a multi-select post relationship filter in the Search and Pagination panel so you can filter the table by Event. By default, all Events are shown, but you can use the filter to change that.

Now we have a problem with the other 3 filters - Country, Gender, and Age Group. Country and Age Group don't exist right now, so you would have to set those up as custom fields somewhere. The Player Gender field is not associated with the intermediary post type, so we cannot sort or filter by it right now. The only way to work around this is to copy information from the Event and Player posts into the intermediary post type. Manually this will be tedious, so ideally you would set up some custom code to automate this process. Whenever an intermediary post is created by associating an Event and a Player, the custom code would automatically grab the data from the Event and Player posts and insert it into the intermediary post. This will allow us to sort and filter by those other data fields.

Before we get into that, I want to pause and get your feedback. There is a lot of information to process here, so please feel free to ask any questions you have now.

#1480235

Hello Christian, I really appreciate your help so far with my issue.

I have seen the setup you made. But I still have an issue, the ranking table is meant to show the best performance of each player overtime per event. E.g if a player has competed in several 200M events, I should see only the best performance in that ranking table and the related data(event date, club, coach etc).

It should basically show the best performance of every player that has ever competed in that event. Which is where the filter comes in. Users can say show me the ranking of all females in Age group 10, in all 200m events.

#1481295

There's nothing exactly like this type of inter-result filtering built into Views. You could handle something like this a couple of different ways:
1. In the intermediary post type, create custom fields for Personal Best time in 200, Personal Best time in 400, etc. so that there is a Personal Best time for each event type. Leave the field empty if the time for that Player / Event is not his or her Personal Best for that event type. If the time is his or her Personal Best, copy that time in to the Personal Best time field for the corresponding event type. Add a Query Filter to the View based on this new Personal Best field, where the field is not equal to an empty string value. This will prevent results which are not personal bests from appearing in the View results.
2. Use the wpv_filter_query_post_process PHP API to manipulate the View results based on performance for each Player in all Events. We have documentation for this API available here: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

#1484199

Okay. I will look at (2) and get back to you.

#1486151

Hello, I have tried but can't seem to figure out how to merge both ideas/solutions below, could you please help set up a demo in the test site we have been working it.

"Now we have a problem with the other 3 filters - Country, Gender, and Age Group. Country and Age Group don't exist right now, so you would have to set those up as custom fields somewhere. The Player Gender field is not associated with the intermediary post type, so we cannot sort or filter by it right now. The only way to work around this is to copy information from the Event and Player posts into the intermediary post type. Manually this will be tedious, so ideally you would set up some custom code to automate this process. Whenever an intermediary post is created by associating an Event and a Player, the custom code would automatically grab the data from the Event and Player posts and insert it into the intermediary post. This will allow us to sort and filter by those other data fields."

"1. In the intermediary post type, create custom fields for Personal Best time in 200, Personal Best time in 400, etc. so that there is a Personal Best time for each event type. Leave the field empty if the time for that Player / Event is not his or her Personal Best for that event type. If the time is his or her Personal Best, copy that time in to the Personal Best time field for the corresponding event type. Add a Query Filter to the View based on this new Personal Best field, where the field is not equal to an empty string value. This will prevent results which are not personal bests from appearing in the View results."

#1487337

could you please help set up a demo in the test site we have been working it.
Not really, the demo site we have been working on does not allow us to upload custom code in a plugin, custom theme, or to create custom code snippets. We would need a more flexible demo environment to set up something with custom code. Do you have a development environment available?

#1487463

Yes, is there I can sare the login details privately?

#1489531

Yes sorry for the delay. Please find private reply fields enabled here so you can share login credentials securely.

#1490237

Okay I have added the Athlete Gender duplicate field to the intermediary post type. The field name is Athlete Gender (For Sorting) and the slug is athlete-gender-sort. You can see the field I added here:
hidden link

Now we want to populate that field value automatically whenever a connection is made in the Players-Events relationship. Here's an example code snippet:

add_action( 'toolset_association_created', 'automate_intermediary_gender_func', 10, 5 );
function automate_intermediary_gender_func( $rel_slug, $parent_id, $child_id, $intermediary_id, $association_id ) {
  if( $rel_slug == 'player-event' ) {
    $gender = get_post_meta( $parent_id, 'wpcf-athlete-gender', true);
    update_post_meta( $intermediary_id, 'wpcf-athlet-gender-sort', $gender );
  }
}

I have added that example as a custom code snippet in Toolset > Settings > Custom Code. For reference here is documentation on this API: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created

Now when you connect an Event and a Player, the Player's gender information will automatically be imported into the intermediary post type. This allows us to filter the View of intermediary posts using the gender information, by proxy. I added the Athlete Gender For Sorting filter to the Players filtered by Event View here:
hidden link

Now you can see the functioning gender filter on the front-end of the site: hidden link

#1499053

Hello, I will get back to you on my attempt to replicate your demo.

#1500597

Okay great, I'll stand by for your update.

#1501319

Hello,
1. The performance field is currently set up as a single field is there any way I can format it as time as the result will be sorted based on the performance field.
2. Sometimes 2 players can have the same performance time, can the rank field be formated such that when 2 two players tie the rank will be repeated e.g we can have 1, 2, 2,4,5

#1501775

1. The performance field is currently set up as a single field is there any way I can format it as time as the result will be sorted based on the performance field.
Not really, there is no "time" data type in Types so it would be difficult to split this into multiple fields and sort by some combination of those values. My suggestion here is to store a number that represents the total time in seconds or milliseconds. This will allow you to sort easily by that field. Then if you want to display that performance time as HH:MM:SS, you have two main options:
- Store the formatted time in a separate custom field and display that field instead of the total time in seconds/milliseconds
- Create a custom shortcode that translates the total time in seconds or milliseconds into the format you want to display.

2. Sometimes 2 players can have the same performance time, can the rank field be formated such that when 2 two players tie the rank will be repeated e.g we can have 1, 2, 2,4,5
No that's not possible in the current setup, because you told me:
"(a) Rank -(this is just numbering the output from 1 till the last item in the result)"
You would have to store the rank for each item as a custom field if you want something other than an incremented count of items in the results.

#1502725

Please do you have a demo to show how to achieve either of the solutions suggested in toolset
- Store the formatted time in a separate custom field and display that field instead of the total time in seconds/milliseconds
- Create a custom shortcode that translates the total time in seconds or milliseconds into the format you want to display."