Skip Navigation

[Resolved] Filter by taxonomy, in Many-2-many relationship.

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

Problem:
Check if the parent post has specific taxonomy terms.
For example:
1) Ydelser (services in danish)
2) Personer (staff in danish)
3) Relationer (relations in danish, a intermediary as guided in your documentation).
Staff has a taxonomy named "Positions", which has the terms "Jurys" & "Secretaries".

I want only "Secretaries" displayed from the Staff, in the service, not all staff.

Solution:
1) Create a content template for display the information of parent "medarbejdere" post, for example the content template "medarbejdere-info", with below codes:

[wpv-conditional if="( has_term('Secretaries', 'positions', null) eq '1' )" ]
<li>[wpv-post-link]</li>
[/wpv-conditional]

Please replace the "Secretaries" with term's name and replace "positions" with your custom taxonomy slug.
2) Display the parent information with the content shortcode:

...
[wpv-post-body view_template="medarbejdere-info"  id="$medarbejdere"]
...

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/

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
- 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)

Author
Posts
#394561

Hello there.

Im having a little challenge..

I have 2 post types, with many to many relationships.
1) Ydelser (services in danish)
2) Personer (staff in danish)
3) Relationer (relations in danish, a intermediary as guided in your documentation).

Staff has a taxonomy named "Positions", which has the terms "Jurys" & "Secretaries".

Each "Service" page, it shows the "Staff" linked to it using [wpv-post-link id="$medarbejdere"].. It works perfect so far.

The trick/issue here is that i want only "Secretaries" displayed from the Staff, in the service, not all staff.
The staff member displayed must ofcourse respect the relation created already, so it should only show the staff member that has a relation to that service, with above mentioned in focus (from specific term)..

I hope it makes sense.

#394911

Dear thomas,

I suggest you try with Views shortcode [wpv-conditional] to check if the parent "Staff" post has term "Secretaries", then display the link, see our document:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/
Section "Checking if a post has a specific term assigned"

#394965

Hi Luo, thanks for assisting me.

The view is querying "Relations" - the relations doesnt have terms, so i dont know how i should make a conditional statement to check the terms? The terms are never linked to the intermediary type, only the staff.. Therefore, i dont think the above solution will work..

#394967

The code i am using:

Post relationship filter: Select posts that are children of the Post where this View is shown.

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<ul class="nice-list">
  <wpv-loop>
    <li>[wpv-post-link id="$medarbejdere"]</li>
  </wpv-loop>
</ul>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[/wpv-no-items-found]
[wpv-layout-end]
#395205

I suggest you try this:
1) Create a content template for display the information of parent "medarbejdere" post, for example the content template "medarbejdere-info", with below codes:

[wpv-conditional if="( has_term('Secretaries', 'positions', null) eq '1' )" ]
<li>[wpv-post-link]</li>
[/wpv-conditional]

Please replace the "Secretaries" with term's name and replace "positions" with your custom taxonomy slug.

2) Edit the view you mentioned above, modify the codes from:

...
    <li>[wpv-post-link id="$medarbejdere"]</li>
...

To:

...
[wpv-post-body view_template="medarbejdere-info"  id="$medarbejdere"]
...
#396156

Hi Luo.

I still cant get it to work.
I have created the content template, and modified the code as suggested.

If i remove the conditional (check for term), the view shows up as normal, meaning that the view combination is okay. The problem is the validation. I have double checked that the taxonomy slug is correct, and tried putting in the term with both capital and lowercase but nothing seems to be output. - again, if i remove the conditional, it seems to query the link, so the setup is okay.

Did you manage to make it work with the suggested combination?

Thanks for your support, i appreciate it.

#396186

Yes, it works in my localhost, if you need more assistance for it, please duplicate same problem in a test site, and fill below private detail box with login details, also point out the problem view URL and page URL, I need test and debug it in a live website. thanks

#397075

Thanks for the details, I did below modification in your website:
1) When open the problem Views and content template, I see it is blank in the content area, and a lots of javascripts errors, and the ftp access you provided is not valid, so I deactivate other plugins, then the Views and content template works fine
2) Edit the problem view "Relationer (Ydelser til Personer)":
hidden link
in section "Loop Output", replace the content template shortcode from slug to title:
From:
[wpv-post-body view_template="relation" id="$medarbejdere"]
To:
[wpv-post-body view_template="Relation" id="$medarbejdere"]
3) in section "Templates for this View", content template "Relation", modify the codes as below:

<li>[wpv-post-link]
[wpv-conditional if="( has_term('partnere', 'personale-type', null) eq '1' )"]
This post has term "Partnere"
[/wpv-conditional]
</li>

See the result post in front-end:
hidden link

Please check if it is fixed. thanks

#397116

Hi Luo.

Thanks for your help, it works perfectly.
I doublechecked the ftp info before i sent it, and it was correct, i think the problem is that the webhost provider has a stupid setting so you cant use hidden link but you must use hidden link (very stupid) and i have had problems connecting though software as Filezilla etc.

Never the less, you managed to fix it even without - very nice and thank you.

I see that my biggest error was that the template name should have been Relation instead of relation.

It works perfect now - thanks alot, i will definately remember this solution for future projects 🙂

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