Skip Navigation

[Resolved] I need help regarding search based on a taxonomy

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

Problem:
How to display linked posts based on shared taxonomy

Solution:
Create a View that will be added to a page that shows the first post type (either singularly or in a loop) which displays the second post type. This view needs a taxonomy filter adding to "Select posts with taxonomy: ... the same as the current post in the loop" which specifies the shared taxonomy.

Then set what content to output as normal.

Relevant Documentation:
https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/

This support ticket is created 7 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
- 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+01:00)

This topic contains 5 replies, has 2 voices.

Last updated by joseE-5 7 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#398589

I have 2 custom types: courses and schedules. the connection is made by a taxonomy (courses taxonomy being used in schedules). it woul be nice to use parent/child relationship but as I am importing courses and schedules using wp-all-import And I have thousands items I could not do that automatically. now, given a course, I want to display its schedules (the ones that are related to a taxonomy with a field that has the same value as the course-code). Is this possible? thanks in advance.

#398725

Nigel
Supporter

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

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

Hi José

I have read your question several times and I think I understand what you are aiming to do, although it sounds a little convoluted, and there may be a simpler solution, possibly by changing how you import your data.

Could you please restate what you would like to achieve, using some specific examples so that I can visualise the problem better? For example
- what are some example courses
- what are some example schedules
- how do these relate to each other
- what do you want to eventually display

If you could let me know and I will get back to you.

#398773

Ok. Lets say I have a course and schedule custom post types with the following custom fields:

course: course-code, course-title, course-description
schedule: course-code, schedule-start-date, schedule-price, schedule-location

One course can have several schedules for different times and locations. Input data is in XML and I use wp-all-import plugin to import all that stuff. The problem is that the parent/child post relationship is based in id and I have not that in the input data (I have course-code but I couldn't use that to import data populating both post types and connecting them all together).

So what I have done was to create o course taxonomy with only the common field (course-code). Then, when I import both schedules and courses, they are connected with the proper taxonomy. So, there is a relationship but is not a direct link from schedule to course but rather mapping to the same taxonomy entry.

Now, what I need is when showing the course list, to be able to jump to the schedules of the current course and get:
- List of schedules (it would be great to be able to present also information about the next schedule for a course)

Plesas let me know if you need more information. Thanks in advance.

#398959

Nigel
Supporter

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

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

If you know a little PHP it would be relatively straightforward to establish your parent > child relationships by running one time only a function after you have imported your content that loops through your course post type and for each course finds schedules with the same course-code and adds the post meta to the schedules to connect them to the course.

If that is an option you add the id of the parent post to the child meta with the key _wpcf_belongs_PARENT_id (where PARENT is the slug of the parent custom post type, e.g. 'course')

If that is not an option then your proposed solution will work.

With your courses and schedules having the taxonomy set equal to the course-code, you need to create a View for showing schedules that are attached to courses.

(You might want to display a single Course and show the Schedules attached to it, or you might want to loop through the Courses and display the attached Schedules of each of them. You could use the same View for each, or you might want to have a different level of detail for the single course and course list results, but the principle is the same.)

So create a new View to display your schedule custom posts. The key is to now add a taxonomy filter to Select posts with taxonomy: course ids the same as the current post in the loop. You then need to set what to content to display.

If you inserted that view in the content template for your courses, for example, then when you view a single course you will see the attached schedules.

If you need some more specific help then do let me know.

#399139

That sounds good. I will check and let you know about the outcome.

#399467

Hi Nigel. Everything is working fine. Thank you for your brilliant support. Now, the only think that I must find out is how to show the schedules in a popup instead of using a different page. I am planning on using popupmaker plugin to make it work. Later, perhaps I will need it also for a CRED form and I think that this will be harder. It would be a great improvement to deliver the functionality directly from CRED.

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