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.
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"
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..
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]
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"]
...
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.
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
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
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 🙂