Skip Navigation

[Resolved] Use post slug as taxonomy filter in view – vs. using relationship filter

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

Problem: I would like to show a list of posts related to the current post. I can use post relationships but I would prefer to use taxonomy terms. How can I use the current post slug as a taxonomy term slug filter?

Solution: You can set up a taxonomy term filter to respond to a shortcode attribute. In the View shortcode, you can place the current post's slug using the wpv-post-slug shortcode. Something like this:

[wpv-view name="Jobs related to this Health Center" healthcenter="[wpv-post-slug]"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-slug

This support ticket is created 5 years, 4 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)

Author
Posts
#1278631
chcact-relationship-filter.png

Hello,

I have a website that has multiple locations (health centers) that use a page template for all the health centers that include views. Currently, there is an included view that lists posts (jobs) that are related to that location. The problem is the manual process needed to edit each job posting on the back end to add the relationship to the location.

I've recently added a front end form for the health centers to manage their own jobs. Added and published jobs only show up in the big list hidden link but not on each health center's page because the relationship is not set up (until done manually). Links to each health center are generated here: hidden link - clicking through to any will show the health center details.

Attached is an image of the relationship filter.

Note that the health center is also used as a taxonomy choice when adding the job, which is also used on the main job page.

So the question:

Can the taxonomy selection for the health center somehow be passed through to the view to act as the dynamic filter? Perhaps by matching the health center post slug/name with the jobs taxonomy slug/name?

Or is there a way to set the relationship using the front end (cred) form? Either automatically through the taxonomy set by they Health Center select box on the form, or (less desirable) by the ability to pick the relationship on the form.

Bottom line: I'm trying to show jobs posted through a front end form in health center pages that dynamically generated within the same template. I'm also trying to minimize the amount of admin intervention and steps needed to post.

Thanks for your help.

#1278751

Can the taxonomy selection for the health center somehow be passed through to the view to act as the dynamic filter? Perhaps by matching the health center post slug/name with the jobs taxonomy slug/name?
Sure, if the taxonomy term slug on the Job post matches the Health Center post slug identically, then you can set up a View of Jobs filtered by taxonomy term, where the term slug is set by one shortcode attribute like "healthcenter". In the Job View shortcode, you can place the current post's slug (the Health Center post slug). Now the filter is dynamically set by the current Health Center slug. Here's an example of the Jobs View shortcode with the nested post slug shortcode:

[wpv-view name="Jobs related to this Health Center" healthcenter="[wpv-post-slug]"]

This dynamic shortcode attribute technique is called "passing arguments to Views" and is described in more detail here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

Or is there a way to set the relationship using the front end (cred) form? Either automatically through the taxonomy set by they Health Center select box on the form, or (less desirable) by the ability to pick the relationship on the form.
The taxonomy term approach is certainly doable, but it requires your term slugs to match the Health Center slugs identically. That can cause problems if you give your visitors the ability to create new HC terms or new HC posts. You would probably have to have some manual intervention in wp-admin to validate the term slugs match the post slugs in every case.

The post relationship approach is also doable. In a one-to-many post relationship, you can add a post relationship select field in the new child (Job) post Form. Your visitors can select the correct Health Center manually, or you can link to the new Job post Form from any Health Center post using a special link URL that sets the parent Health Center automatically. See the guide here: https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

#1278851
job-form.png

Christian,

Using the taxonomy slug as a nested post slug shortcode worked beautifully. Thank you!
Keeping the slugs matched is not an issue as there are rarely health centers added and it will only be by an admin.
As an added bonus, jobs showed up that were never previously related to the health center by the person entering them.

Just a follow-up on the post relationship approach. What should be in place for the post relationship select field to show in the form editor? The Add New Job form does not give me the relationship as an option. I don't see it.

#1278893

Is "center Parent" not the relationship field? It's in the top right area.

#1278905

That, indeed, was it!
Staring me in the face - mocking me...

I was looking for a "Relationships" section of the field choices per the screen shot here: https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

#1278913

My issue is resolved now. It ultimately was an easy solution once I knew what to do. So many options and power that it's a challenge (but a good challenge) to know all the functionality and options. Thank you!