Skip Navigation

[Resolved] Display list of links to CPT based on a one to many 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

Author
Posts
#2609059

Tell us what you are trying to do?
I have a Toolset CPT for Locations and a toolset CPT for Services. I want to show a list of related services for the location.
I created all the locations, an archive to display and a template for the individual listing.
I created all the Services, an archive to dispaly and template for each service.
Next I in one location I 'connected' all the services for that location.

I tried creating a view for services, and listing the links, but it just crashes the site so I removed that content block.

I want the list to look like this:

• Service 1 (with a link to the related service CPT)
• Service 2 (with a link to the related service CPT)
• Service 3 (with a link to the related service CPT)
• Service 4 (with a link to the related service CPT)
• Service 5 (with a link to the related service CPT)

One of the issues, in though it shows the relationship of the service in the view, in the selection of fields, it never show the service fields, i.e, the corresponding dynamic way to link to Service Post Title with link. I tried some of the other methods and thought I was getting somewhere but then the template just stopped working and displaying all info.

This picture on your documentation seems to show that i would see the corresponding fields and relationships and I can never see this... https://toolset.com/wp-content/uploads/2020/09/toolset-post-relationships-selecting-fields-for-intermediary-post-type-500x299.png I see Services, but I can select anything to do with "services" like the post title to the service or link to create a dynamic loop

Is there any documentation that you are following?
https://toolset.com/course-lesson/many-to-many-post-relationships/
https://toolset.com/forums/topic/create-a-view-with-toolset-blocks-that-only-shows-content-of-relationship/
https://toolset.com/course-lesson/displaying-related-posts/

Is there a similar example that we can see?

Any of the above examples to show connected relationship and show unordered list of all associated posts

What is the link to your site?

Communityhealth.greenmountain.marketing

SERVICES CPT (pending content but skeleton is here) hidden link
Locations: hidden link
Location with associations to connected services: hidden link

#2609191

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

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

Your understanding is correct and in the loop of the view that shows the related posts, the custom fields from those related posts should be available as the dynamic source.

Are you seeing any errors or warnings in the browser's console or in the server's error logs, when the content template crashes?

To troubleshoot this, I'll need to see how these content templates and the views are set up in the admin area. Can you please share the 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

#2611755

Also, ideally I would be able to filter providers by their assigned location in addition to the provider taxonomy on this page: hidden link (I do have filters set up for a taxonomy.) Thank you for any help in advance!

#2611955

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing these details.

1. I noticed a number of '403 errors' in the browser's console when viewing the editor screen for the content templates and the WordPress Archives.

Looks like something on your website is blocking the REST API calls, which are needed for the blocks-based editor (Gutenberg) to function properly. Most likely it could be due to security or firewall plugin.

2. In the content template 'Template for Locations', a location post that is selected as a preview post in the 'View with' field doesn't have any related 'Service' post attached.
( screenshot: hidden link )

When you plan to show the fields from the related posts as the dynamic source, it is a good idea to select a preview post that does have at least one related post.

3. In the archive for the providers, if you'd like to include a filter for 'Locations', you can add the post relationship filter field, the same way as you added the filter for the taxonomy.

In the archive's 'WordPress Archive Search' block, you'll use the 'Add Search Field' button to add the 'Post relationship or repeatable field groups owner' filter.

Important note: The website kept on becoming inaccessible for me, while I was looking into the different admin area sections. I'll recommend getting in touch with your hosting support team, to investigate why it stops responding abruptly and if the available server resources are getting exhausted.

#2612019

Thank you Waqar,

1) I will take a look at the hosting and REST API. I did just recently open up the firewall so you wouldn't have issues logging in. I find sometimes Toolset works flawlessly, other times it behaves as you describe which is very frustrating. Is there an ideal hosting configuration you recommend?

2) The 'Template for Locations' which displays each individual location,has a connection to 'services'. Services are currently assigned to all "health center" (taxonomy) locations. I was able to list the services connected on this location just below the image which i can see in your screen shot, it shows:

/service/primary-care
/service/behavioral-health

in this location, I connected several services also:

hidden link

In the template for locations, I am using this shortcode though I know it doesn't go far enough or I am not doing this correctly.
[types field='services-at-this-location' separator=''][/types]

hidden link

Question: As this template is only meant to be used to display locations and their associated data, are you suggesting I need to also check other boxes for usage like "location services intermediary posts?"

3) I gave this a try, however when I add it doesn't produce what I expect (which would be a list of the "locations" that can get filtered. In stead I get this wierd array? that looks like this? hidden link

hidden link
I have left the filter in here...

Also on the provider's archive output.
I tried using this shortcode to simply display the associated location or locations for each providers but it didn't work. I can use some guidance for how to structure the url? Or how best to go about this.

[wpv-control-post-relationship][wpv-post-title item="@location-provider.association" url_param="#"][/wpv-control-post-relationship]

Thank you for your help in advance.

Sincerely,

Kasia

#2612027

quick PS, this suggests REST API is working, and working for toolset?

hidden link

hidden link

#2612941

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for waiting, as I had an unusually busy forum queue after the weekend.

Just wanted to let you know that I'm working on it and will share my further findings, as soon as I can.

#2615063

I still need assistance can you please help?

#2615387

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

I apologize for the delay in getting back to this ticket.

I'm currently working on it and will share a detailed reply shortly.

Thank you for your patience.

regards,
Waqar

#2615677

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

First, thank you so much for waiting as this troubleshooting turned out to be way more complicated.
(mainly because of the server 403 issues )

> 1) I will take a look at the hosting and REST API. I did just recently open up the firewall so you wouldn't have issues logging in. I find sometimes Toolset works flawlessly, other times it behaves as you describe which is very frustrating. Is there an ideal hosting configuration you recommend?

----------------------------

- I couldn't work at all with the template and archive editor screens on your website, due to those 403 errors and pages getting unresponsive.

There is something definitely related to your hosting server or Firewall settings since your website's clone on my test server doesn't show these errors.

If your hosting support team can't find the cause of this, switching to a different hosting would be a good idea.

Our recommended server configuration information is available at:
https://toolset.com/toolset-requirements/

=============================================================

2) The 'Template for Locations' which displays each individual location,has a connection to 'services'. Services are currently assigned to all "health center" (taxonomy) locations. I was able to list the services connected on this location just below the image which i can see in your screen shot, it shows:

/service/primary-care
/service/behavioral-health

in this location, I connected several services also:

hidden link

In the template for locations, I am using this shortcode though I know it doesn't go far enough or I am not doing this correctly.
[types field='services-at-this-location' separator=''][/types]

hidden link

----------------------------

- For this point, I'm a little confused as I see some duplication.

The website has a 'Services' CPT with 19 published posts.

And this is already joined with the 'Locations' CPT through the 'Location Services' many-to-many relationship.
( screenshot: hidden link )

In the presence of this linkup, I don't see the need for the custom field 'Services at this Location', which is added in the field group 'Location Information'.

It is repeating the same services as options that are already added as posts in the 'Services' CPT.
( screenshot: hidden link )

This means that you don't need this custom field or its shortcode [types field='services-at-this-location' separator=''][/types].

You'll just open each location post's edit screen and connect the relevant service post(s) through the 'Location Services' section.
( screenshot: hidden link )

After that, in the template 'Template for Locations', you can use a view to show the list of only the related services posts, as explained here:
https://toolset.com/lesson-placement/lesson-placements-1729031-1730449/#displaying-many-related-items

=============================================================

> Question: As this template is only meant to be used to display locations and their associated data, are you suggesting I need to also check other boxes for usage like "location services intermediary posts?"

----------------------------

- Your understanding is correct and the 'Template for Locations' is only needed for the single 'Locations' post pages.

You don't need to check any other post type for its 'usage' settings.

=============================================================

3) I gave this a try, however when I add it doesn't produce what I expect (which would be a list of the "locations" that can get filtered. In stead I get this wierd array? that looks like this? hidden link

hidden link
I have left the filter in here...

Also on the provider's archive output.
I tried using this shortcode to simply display the associated location or locations for each providers but it didn't work. I can use some guidance for how to structure the url? Or how best to go about this.

[wpv-control-post-relationship][wpv-post-title item="@location-provider.association" url_param="#"][/wpv-control-post-relationship]

----------------------------

- In the archive 'Community Health Providers', you'll see that there are two levels of relationship search filters added.
( screenshot: hidden link )

You don't need the second level that deals with location provider intermediary posts. You can change that to just include the one for the 'Locations Providers' and the options will only show the location posts.
( screenshot: hidden link )

=============================================================

I hope this helps and please let me know if you have any follow-up questions.

#2616669

Thank you Waqar. Lots of helpful information. I appreciate your patience and expertiese. I should be able to start refining the display and remove redundant fields.

There is one remaining issue I still need help with:

On the provider's archive output:
hidden link

I want to show the the connected location, or locations, for each provider in the output. What is the best way to display this information?

I tried using the following shortcode to display the location:
[wpv-control-post-relationship][wpv-post-title item="@location-provider.association" url_param="#"][/wpv-control-post-relationship]

Because when I tried to add a "view" to the archive template to display this info it says " Nested views creation is not supported at the moment."

For example, if I click "Community Health Pediatrics" all the correct providers show, but I want the output to inlude this information. Right now below the View Provider Button it says: "The url_param attribute is missing."

Thank you in advance for your help.

#2616681

I have another question. Is there new information for this solution? I cannot enable views in the editing experience in 3.4.19:

https://toolset.com/forums/topic/how-to-manage-edit-delete-views-created-in-toolset-blocks/#:~:text=These%20views%20can%20be%20managed,and%20select%20the%203rd%20option.

Thank you for answering this and my previous question just above.

#2617591

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Glad that I could help.

> Because when I tried to add a "view" to the archive template to display this info it says " Nested views creation is not supported at the moment."

- Yes, nesting of blocks-based views is not supported inside other views and the archives. For this, you'll need to use the classic/legacy view.

Please go to WP Admin -> Toolset -> Settings -> General and select "Show both the legacy and Blocks interface and let me choose which to use for each item I build" for the "Editing experience" field.

After that, you'll be able to create a new classic/legacy view from WP Admin -> Toolset -> Views.

This view will be set to show the location posts, with a relationship query filter, as explained in this guide:
https://toolset.com/documentation/legacy-features/views-plugin/displaying-related-child-posts/

Once the view is ready, you can include it in the loop of the archive for providers, using the view's shortcode, added in a 'Fields and Text' block:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-view )


[wpv-view name="Name of the view"]

> I have another question. Is there new information for this solution? I cannot enable views in the editing experience in 3.4.19:

- I do see the option available for this on your website, as suggested in the other support thread.
( screenshot: hidden link )

Can you please enable that and let me know if doesn't work?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.