I am building a simplified CRM for my office. Each workmate has a number of companies assigned and as a business objective, they have to "contact" each company at least once during the year.
I am creating a table view with the Legacy View editor (WAY better than block editor, please DO NOT DISCONTINUE IT!). The view is based on the CPT called "AZIENDE" (Companies) and I would like to highlight the row in a different color IF AZIENDA has at least ONE child in related CPT "INTERVENTI" (contacts).
Can you please help?
Hello,
It is possible with nested views, for example, see below sandbox website:
Login URL: hidden link
1) Setup parent post view:
hidden link
- Query "AZIENDE" posts
- In view's loop, display a HTML tag with post ID attribute:
<li class='aziende-[wpv-post-id]'>[wpv-post-body view_template="loop-item-in-aziende-view"]</li>
2) Child post view:
hidden link
- Query "INTERVENTI" posts
- Filter by:
Select posts in a AZIENDEs INTERVENTIs relationship that are a related to the current post in the loop.
- In view's loop, display CSS codes, like this:
<style>
.aziende-[wpv-post-id item="@aziende-interventi.parent"]{
background-color: aqua;
}
</style>
3) Create a page, display the parent post view:
hidden link
It works fine.
For your reference.
Thinking it would be probably done with a code snippet instead of involving nested views, I omitted to clearly explain the whole structure and relationships scheme of the website, and now I see it could be a problem... If the structure was the one you replicated in the sandbox website, in fact, it would work perfectly.
I see it's working because I can see the "no items found" besides the name of the company when I run the view, but i am still not getting the highlight, probably because I am not targeting the element in the right way, being the names slightly different in my website.
So, before getting into a lengthy explanation of the whole structure of the cpts (that maybe is not yet necessary), can you explain what is it that you're targeting in the
.aziende-[wpv-post-id item="@aziende-interventi.parent"]
style?
What is the ".aziende-" part of the css referred to?
Q) What is the ".aziende-" part of the css referred to?
It is CSS class name of step 2)
<li class='aziende-[wpv-post-id]'> ... </li>
It simply styles the specific item of parent post view.
Yes, but you're targeting it with a relationship (item=@aziende-interventi.parent) and since my structure isn't the same as yours, the highlight is not working.
Would you like me to explain the whole website structure so you can better understand why I asked you what that bit of code is referred to?
If you'd rather login and see for yourself (the website is in italian, that's why I was offering to explain!) I can give you full access.
Thank you!!
Please provide your website credentials in below private message box, also point out:
- Parent post view URL
- Child post view URL
- Page URL, where I can test the result in frontend.
Thanks for the details, I am checking it in your website, will update here if find anything
I have done below modifications in your website,
1) edit parent post view:
hidden link
in section "Loop Editor", line 20, change it to:
<tr class="azienda-[wpv-post-id]">
2) Edit child post view:
hidden link
in section "Loop Editor", line 6, change it to:
.azienda-[wpv-post-id item="@intervento-per-azienda.parent"]{
Test it in frontend:
hidden link
It works fine. please test again
I found a much simpler solution involving the creation of a shortcode, which is way more flexible, following this thread : https://toolset.com/forums/topic/conditional-check-if-there-are-related-posts/
Thank you for your help, anyway! Have a good day