Skip Navigation

[Resolved] Nesting view in content template within loop produces no results

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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Waqar 10 months, 1 week ago.

Assisted by: Waqar.

Author
Posts
#2677631

*** Tell us what you are trying to do?
I am building a contact database for a client that is a national organization with local chapters.

I have created custom content types for Contacts (the names and contact information for the individuals) and Locals (local chapter information: address, local name, the URL for the local website etc). They are related in a many to many relationship as (unfortunately) individual contacts can be related to multiple locals.

In the contact listing view I want to be able to list the names each contact, their position, and their local chapter like this:

Robynn Earle, Treasurer, Local 90019

I have created a content template with a view in it that lists the contact's first and last name, their position, then looks up the their local. But the view returns no results when it should.

*** Is there any documentation that you are following?
https://toolset.com/course-lesson/displaying-related-posts/ but it's not at all helpful.

*** Is there a similar example that we can see?
I wish.

*** What is the link to your site?

hidden link is the page in question.

#2677675

Hi,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot this, I'll need to see how this view and the content template are set up in the admin area.

Can you please share temporary admin login details in reply to this message?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2678047

Thank you for sharing these details.

The main challenge here is that the template 'Local Contact Listing' is being used on the single 'Contacts' post page, as well as in the view 'Main Directory Search' on the directory page.

The relationship query filter which shows only the related locals, works when used on the single 'Contacts' post page, but not when it is in a loop of a view that is showing the contacts posts.

To find a common usage for both these cases, I've switched the view to show all local posts, but with a relationship query filter:
( screenshot: hidden link )

Select posts in a Local members relationship that are related to the Post with ID set by the shortcode attribute wpvrelatedto.
eg. [wpv-view name="view-name" wpvrelatedto="123"]

Since we can't pass the shortcode attribute value to the view through the 'View' block, I've updated the shortcode for the same view that you had on the top, to include this attribute instead:
( screenshot: hidden link )


[wpv-view name="this-contacts-local-v2" wpvrelatedto="[wpv-post-id]"]

The use of the '[wpv-post-id]' shortcode will ensure that the correct target 'contact' post's ID is passed to the view. On the single contact post, it will be the current contact post ID and in another view's loop, it will be the current contact post's ID coming from the loop.

You'll also note that I've added a hidden container block inside the template and moved the actual view block inside it. That is because we want to show the view's instance coming from the shortcode, but not from the view block.
( as that view block doesn't have the target 'wpvrelatedto' value, it shows all local posts )

#2678079
Screen Shot 2024-01-11 at 6.12.55 PM.png

Thank you so much Waqar. There is no way in a million years I would have ever figured this out.

I have a nit-picky question, though. When I edit the content template you created to insert the name of the local after the leader's name, if I look in HTML mode I see the 'Fields and Text' fields surrounded by an H4 tag. Then I see the 'this-contacts-local-v2' view underneath.

(hidden link)

When rendered, this puts the name of the local on a separate line in plain text, below the name of the contact.

When I change the markup, for example, to surround both the 'Fields and text' fields and the local name lookup view in the same tag — whether an H4 or div it doesn't seem to matter — the 'this-contacts-local-v2' view breaks. Nothing is rendered.

I expect there's probably a way to render both elements inline so that they appear as intended, but it would be better for accessibility and just plain old efficient markup if both the local contact's name, position and local name could be in the same HTML element.

The editor window allows it, but it breaks.

I've left the template as you created it but if you have a minute could you look at it to see if you can reproduce the problem and/or tell me what I can do to fix it?

cmkl

New threads created by Waqar and linked to this one are listed below:

https://toolset.com/forums/topic/split-showing-views-content-in-a-single-line/

#2678433

Thanks for writing back and I'm glad that I was able to help.

I've created a separate ticket for your question about making the view's content in line and will follow up on that shortly.
( ref: https://toolset.com/forums/topic/split-showing-views-content-in-a-single-line/ )

You're welcome to mark this ticket as resolved and start a new one, for each new question or concern.

#2678552

Problems persist but this is solved.