Skip Navigation

[Resolved] Highlight post in table view if the post has children in a specific relationship

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)

This topic contains 8 replies, has 2 voices.

Last updated by Silvia 1 year, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#2603201

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?

#2603861

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.

#2603915

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?

#2603921

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.

#2603927

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

#2603929

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.

#2604291

Thanks for the details, I am checking it in your website, will update here if find anything

#2604299

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

#2604649

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