Hi -- I had previously logged a support request on this issue and you gave me an answer but that didn't resolve the issue for me. (https://toolset.com/forums/topic/displaying-archive-lists-with-multiple-post-relationships/)
I'm trying to display a nested list of custom posts that are in many-to-many relationships with each other. I have job listings that belong to one (or a few) organizations. I want to display a list of the organizations, with the jobs that they have available in a list underneath them. One solution that seemed to work is the following but that was duplicating the organizations where there is more than one job for that organization:
1. A View displaying staffing posts that have an expiration date > today with the following loop code
<wpv-loop>
[wpv-view name="parent-orgs-final-1"]
</wpv-loop>
2. The "parent-orgs-final-1" view displaying organization posts that are related to the current post in the loop with the following code:
<wpv-loop>
<div id="org-id_[wpv-post-id]" class="parent-organization">
<span class="org-acronym">[types field='org_acronymn'][/types]</span> <span class="org-title">[wpv-conditional if="( '[wpv-post-title]' ne '0' )"]([wpv-post-title])[/wpv-conditional]</span>
</div>
[wpv-view name="listing-child-staffing-posts"]
</wpv-loop>
3. The "listing-child-staffing-posts" view that displays posts that are related to the current post in the loop, but now again selecting staffing posts:
<wpv-loop>
[wpv-conditional if="( '[wpv-post-date format='U']' gt 'PAST_MONTH(1)')"]<span class="new-flag"><img src='/wp-content/uploads/new_bug2.gif' alt="New"></span>[/wpv-conditional][wpv-post-link], [types field='secondary_desc'][/types] (Posted: [wpv-post-date format="m/d/y"]) [wpv-view name="staffing-states"]
</wpv-loop>
I have a similar challenge when trying to display state and country listings but maybe the answer to this will help with that.
Hi Jon,
Thank you for contacting us and I'll be happy to assist.
Based on what you've shared, I understand that the only concern you have with your current solution/approach is that it is duplicating the organizations (and it doesn't matter if the staffings within the organizations are shown repeatedly).
If this is correct, you can use some custom jQuery script, to remove all the duplicated organization entries.
1. In your reply's point 2, you mentioned wrapping your organizations in a div container:
<div id="org-id_[wpv-post-id]" class="parent-organization">
You can update it to:
<div data-id="[wpv-post-id]" class="parent-organization">
2. Next, in the most parent view's "JS editor" tab, you can add the following script, that will cycle through all the organization entries and will remove those which are repeated (i.e. have the same IDs):
// hide all divs with class "parent-organization" to avoid flash of unprocessed organizations
jQuery('.parent-organization').hide();
jQuery( document ).ready(function() {
var seen = {};
jQuery('.parent-organization').each(function() {
var dataid = jQuery(this).attr("data-id");
if (seen[dataid])
jQuery(this).remove();
else
seen[dataid] = true;
});
// show all processed organizations
jQuery('.parent-organization').show();
});
I hope this helps and please let me know how it goes.
regards,
Waqar
My issue is resolved now. Thank you!