Skip Navigation

[Resolved] Multiple CPTs in a single view – but 1 CPT needed twice

This thread is resolved. Here is a description of the problem and solution.

Problem:

Use one Toolset form to create parent/child posts at the same time.

Solution:

One Toolset post form can handle only one post, you will need to setup a post form for creating new "Flight Details" post, for example, after user create a new "flight" post, redirect him to the new "flight" post, and display the child "Flight Details" form link

Relevant Documentation:

https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

This support ticket is created 3 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.

Our next available supporter will start replying to tickets in about 1.00 hours from now. Thank you for your understanding.

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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by toddU 3 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1607141

I am trying to determine the best method for creating a view of a trip itinerary.

I have several different post types, all with the custom fields group "Activity Details" added. The custom post types include:
• Games
• Hotel Reservations
• Facility Reservations
• Bus Moves
• Activity Details

The first four are specific and have their own additional custom fields group. The last, Activity Details, is the basic option for adding something to the itinerary.

In the "Activity Details" custom field group, I have a field titled "activity-start". This field is a date/time field.

I have created a view ("Itinerary for Trip") that queries all five of these CPTs and sorts them by activity-start. All is well so far. I can see everything I need and it's ordered by the date/time, like a proper itinerary.

NOW, the big piece missing is flight information. I have created a CPT titled "Flights". I have properly set up my relationships to other CPTs to enter departure city, arrival city, airline, and flight number. The last two main items I need to have for a flight is a "departure-time" and "arrival-time".

MY PROBLEM, is that on the "Itinerary for Trip" view, I want to show TWO items for each flight: 1 with the departure information and a 2nd with the arrival information.

Thus, when a user looks at their itinerary, they will see the departure time (and other related info) at the correct time on the view. They should also see the arrival time (and other related info) at the correct time on the view. Here's a simple version of what I want to see:

8am Flight departs Chicago
10am Flight arrives Miami
12pm Check In to Hotel
4pm Game vs. XYZ Opponent

If I add the "Activity Details" field group to Flights, I can enter only one time. Say I enter the departure time. Then I add the Flights CPT to the View query. What I get is the departure info on the view. But I don't get anything for the arrival time. In my above simple example, I cannot get the "10am flight arrives Miami" line.

How can I set this up to get both departure and arrival times in this view?

#1607845

Hello,

How do you setup the custom fields in post type "Flights"?

Here are my suggestions:
1) Add 4 fields in post type "Flights":
- departure time
- departure city
- arrival time
- arrival city

2) Create a content template "flights-information"
Display above 4 fields in two rows

3) In "Itinerary for Trip" view's loop, you can use [wpv-conditional] shortcode to check if current item is a "Flights" post then display above content template, for example:

[wpv-conditional if="( '[wpv-post-type]' eq 'flights' )"]
Here display the content template of step 2:
[wpv-post-body view_template="flights-information"]
[/wpv-conditional]

Please replace "flights" with "Flights" post type slug

More help:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-conditional
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-post-body
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-post-type

#1608155

Thank you for the suggestion. Unfortunately, that will not do what I'm needing. That will give me an itinerary that looks like this to the end user:

8am Breakfast
10am Depart Chicago
Arrive Miami
12pm Company Meeting Starts
6pm Dinner

What I need is something like this:
8am Breakfast
10am Depart Chicago
12pm Company Meeting Starts
1pm Arrive Miami
6pm Dinner

On top of that issue, I'm not sure how I would sort it. As of now, I'm sorting by the field 'activity-start' that is in the other post types via activity-details-field-group. With two different date/time fields per your suggestion, how would the flight time(s) get sorted with the rest?

My best solution to this problem so far is to create CPT for "Flights" and a second CPT called "Flight Details". Then in "Flight Details", I add the activity-details-field-group. Create a one-many relationship where Flights is one and Flight Details is many. So my workflow is to create a Flight first (dep city, arr city, airline, flight number) and then add a new "Flight Detail" for departure and another one for arrival. Each "Flight Detail" has one field for activity-start and then the title displays 'Flight Arrival' or 'Flight Departure'.

Then, in my view, I am querying "Flight Details" instead of "Flights". This means I am querying all CPTs that have the activity-start field and can properly sort.

The problem with this...is the difficult, cumbersome, and convoluted method of entering one flight. At least, it's difficult to do on the back end. With this workflow, is it possible for me to make this data entry easier by using CRED forms? Can I use a single CRED form to enter in the four main fields for the flight (dep city, arr city, airline, flight number) and also to add TWO new "Flight Detail" entries?

#1610173

One Toolset post form can handle only one post, "Flight Details" and "Flights" are posts of different post types, so you can not use one post form to create both "Flights" + its child "Flight Details" posts.

You will need to setup a post form for creating new "Flight Details" post, for example, after user create a new "flight" post, redirect him to the new "flight" post, and display the child "Flight Details" form link, see our document:
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

#1613911

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.