Skip Navigation

[Resolved] Question about automatic relationships between custom post types

This support ticket is created 6 years 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years ago.

Assisted by: Nigel.

Author
Posts
#1193969

Hi there,

One of the nifty features of Toolset is its ability to visually create and manage post relationships. To some extent my question is a little strange because it involves bypassing that wonderful interface.

I am developing a course catalog for a college and have two custom post types: Course and Section. A Section is an instance of a Course.

Using "the Toolset way," I'd need to add a new Section post and in the backend click "Connect existing Course." This is very tedious if I have 100+ sections and need to associate Sections with Courses 4 times a year. Barf! So, my question: if both Sections and Courses have a field in common—let's call it course number—is there a way to set a view to display a list of courses where the Course's Course Number is the same as the Section's Course Number?

If this were a relational database and I could query it via SQL, the query would look like...
select courses.course_name from courses, sections where course.course_number = section.course_number;

Another way of asking this question is, is there an automatic way to create post relationships—for example, if I were importing Sections via a CSV file with a plugin like Ultimate CSV Importer Pro? I'm trying to reduce the administrative burden on the people who will be doing the data entry.

Saul

PS. I've been corresponding with Nigel about my project for over a week. Can this support ticket be assigned to him?

#1194180

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Saul

"is there a way to set a view to display a list of courses where the Course's Course Number is the same as the Section's Course Number"

You could display sections that have the same course number field value as the "current" course, or vice versa.

If you are comparing something, you have to have something to compare it to, right?

So you could create a View to display courses, add a Query Filter for the course-number field where the value comes from a shortcode attribute (e.g. "coursefield").

Then when you insert the View in, say, a template to display a section (because we need something to compare to), you populate the coursefield shortcode attribute with the value of the course-number field, something like

[wpv-view name="my-view" coursefield="[wpv-post-field name='wpcf-course-number']"]

But this is about displaying courses and sections with a common course number field on the front end.

I'm not sure how it helps with connecting posts in the back end, which seems to be your main concern.

#1194439

Nigel,

Thanks for your response.

What you're suggesting makes sense. Regarding the issue of whether I'm concerned about connecting posts on the back end, the gist of my question was about trying to find a way to avoid associating posts on the back end, so your proposed solution is totally appropriate. But I've realized that even if an archive page can display a list of sections, I still need to access the parent post's custom fields, and the easiest way to do that is by associating the posts via the post relationship field in the back end. Otherwise I think I'd have to create custom PHP function(s) to look up the course details for a given section's course number. Blech. Omitting the post relationship in the back end would also make the connection to the parent course pretty opaque; with the Toolset post relationship field, a user can see, and modify, a course on the section edit page in the WP back end.

I'm still going to try to think about a way to prevent a user from having to manually associate 100+ sections with corresponding courses four times a year. It just seems very tedious.

Can you mark this thread as resolved?

Thanks again, Nigel!

Saul

#1194460

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Will do, good luck!