Skip Navigation

[Resolved] help with many to many relationship

This support ticket is created 4 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

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: Africa/Casablanca (GMT+01:00)

This topic contains 12 replies, has 2 voices.

Last updated by goceR 4 years, 4 months ago.

Assisted by: Jamal.

Author
Posts
#1794013

I have created two post types (brands and section) every brand belong to some of the sections, and every brand has different snippets for every section which belongs. How can i display the different snippets for the brands depending from the sections. I have made template for the listing of the brands for every section but i can't solve the problem with displaying the snippets in the view for the section posts.

#1794219

Jamal,

I would like to once again open the discussion for this issue as it is a critical one for us moving forward with toolset as our main plugin of choice.

Just to elaborate on what we're trying to do.

Brands - are review pages of casino brands
Sections - are pages that show a list of Brands(using Toolset)
Snippets - are custom text snippets that need to be shown on each Brand listing

We want to show a different predefined snippet for every brand depending on the section page shown. To show you an example I will quote once again what I've outlined in my first most detailed post:

"Here is what I mean:

This is a sectional page of canadian brands listed:

hidden link

You can notice in the listings the casino "Captain Cooks" has a one sentence(snippet) in the listing:

hidden link

"Captain Cooks has an exclusive offer for Canadians. Register and get free no deposit bonus of 100 spins on the Megs Moolah progressive jackpot – worth millions of dollars."

But, if you go ahead and check the following section page for UK:

hidden link

You will notice that the same casino "Captain Cooks" is listed again, using the same tempalte, but the snippet is a different sentence:

hidden link

"Sign up at Captain Cooks casino and get no deposit bonus of $500 in your account that can be used to play games for free 1 hour. UK players accepted!""

Please take some time to understand this. It is a very important feature and we would like to see it in ToolSet. Elementor does this almost perfect in combination with AFC, there is no reason why ToolSet will be behind on this one.

#1794631

First, I'll need to ask one question. How many snippets will be there for a specific section and specific brand? For example "Captain cooks" for "Canada"?
If there will be only one snippet, you should enter the snippet in the custom fields of the intermediary post type of the relationship "brand-section". Which means that the following snippet should go into the fields of the relationship.
"Captain Cooks has an exclusive offer for Canadians. Register and get free no deposit bonus of 100 spins on the Megs Moolah progressive jackpot – worth millions of dollars."
Should go here hidden link when editing the brand "Captain cooks", or here hidden link when editing the section "Canada".
Then, to display the snippets of each "Brand" inside the section, it will be very simple. You will create a view that queries the "Brands" related to the current section. And inside the loop, you will display, the title of the brand, and the snippet from the intermediary post.

Currently, you are saving the snippets on a repeatable group for brands. But there is no way to link each snippet to the relevant section. Even if we can build some way, why not simply use the built-in way of Toolset many-to-many relationships(the custom fields of intermediary posts).

If, on the other hand, you might have several snippets for a specific couple(brand, section), we will need to discuss what is the logic to decide what snippet to display.

Looking forward to your reply.

#1794769

The thing is we need to have as many snippets as there are section pages for each brand page. So not only one. We currently have a repeater field in place, but that's because we experimented with it. It does not mean we want to solve it with a repeater field. We are open to any suggestion on what is the best approach for this.

In the version built with Elementor of the website, we have solved this with custom fields. We create a new custom field under the brands custom post type for each section. So whenever we add a new section page we add a new custom field under brands.

For example if the following are section pages:

Canada
USA
Australia

We would have the following custom fields under Brands:

Canada snippet
USA snippet
Australia snippet

And we would enter the snippet we want to display on each section page in that custom field. For example on the brand page Playamo Casino we would fill the three custom fields mentioned above with the snippet we want to show on every section page respectively.

With elementor there is an option to show dynamics content depending on the page. So in the brand listing template we add all the custom field snippet texts, but we set them to show custom field "Canada snippet" only when Canada section page is loaded, USA snippet when USA section page is loaded, Australia snippet when Australia section page is loaded. And it works for us well. We were hoping to solve this with Toolset better, because well Toolset seems better. 🙂

Everytime we're adding a new section page in the elementor version of our site, we need to
1. create a new custom field in brands with the same Section Page name + snippet,
2. edit the brand listing template to add the new custom field in there
3. set the new custom field in the template to show only when its respective section page is displayed.

This is achieved with a separate addon for elementor.

So it doesn't need to be a repeater field. Anything that will help us achieve this would be great.

#1795633

Ok. So for Canada, there will be only one snippet for the Brand "Captain Cooks", right?
In that case, it is better to use the custom fields of the relationship, instead of custom fields of Brands, or Sections. Just Like I explained in my previous reply.

The snippet should go here hidden link when editing the brand "Captain cooks", or here hidden link when editing the section "Canada".

Then, you will create a view that will display the related posts. The title, logo of the Brand, will be taken from the "Parent" "Brand", the snippet will be pulled from the intermediary post.

Would you like me to prepare an example for you on a test site on our platform? Or you want to enter the snippets as I suggested on your website and I'll prepare an example there for you?

#1796535

We have enter the snippets for the "USA" section - hidden link , now we'll like u to prepare an example on our website, because we tried but with no success.

#1796767

I am not sure if we are testing on the same site. I could not find the snippets you added on your screenshot.

I tested on hidden link

So, check USA post here: hidden link
And see how I added the snippet to the relationship fields hidden link

Then check this template where I worked hidden link

And check its preview for the USA section hidden link
hidden link

Because you are using an outdated version of Toolset Types and Blocks, I used a shortcode to display the snippet:

[types field="snippet-description" item="@brand-section.intermediary"][/types]

And the trick is to use the item attribute. Read more about it here https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

I have also created a test site on our platform that has the latest release. And I was able to display the snippets with the Single Field block, instead of using a shortcode.
You can log in to this test site with this URL: hidden link
Check how I built the post types and the relationship and its field. Then check the content template here hidden link
And the results here hidden link

I hope this explains how to use the relationship fields, and how to display the intermediary(relationship) post field.

Let me know if you have any questions.

#1796805

Because we are not testing on the same site here is a link from our latest version of the site hidden link

We tried what you suggested but unfortunately we did not had any results. There is something that we are missing...
Here are the screenshots of what is shown when you edit trough single field and what is shown when we edit it
-> hidden link
->hidden link

#1796839

I am sorry, but I do not understand what did you mean by your last reply.

Please elaborate more. What did you try? Where did you try it? From where are the screenshots taken? Any URLs to check the content template/view or on the Frontend?

Is there something on the examples that I provided that is not clear?

You shared the homepage of this new staging site. And the homepage includes the content template "Brands Template"(Assigned to Brands), which is wrong. Because the content template expects the current post to be a Brand, but the homepage is actually a page instead of a Brand.

Can you explain what would you expect to get on the homepage?

#1796897

The homepage is fine and it is showing exactly what we want.
The problem are the sectional pages (Canada, USA, etc.) where we actually want to show the snippets in the listing. So if you can edit it or make it on this staging site that would be great.
The examples were clear enough, but although we tried what you suggested, and made comparisons between our template and view and the one that you showed we came to conclusion that there were no differences except the item attribute and the options to choose from the Single Field field that where shown in the screenshots from the previous reply.

-> hidden link
the view that we created for the snippet.

->hidden link
the template for the list that we use in the sectional pages.

#1797467

Jamal,

We have success to display the snippets, but now the problem is that when we enter the snippet on the brand Lucky Days for Sections USA and Canada

hidden link - USA Section
hidden link - Canada Section

the view for the snippets ( Snippet View Test) shows the snippet for Canada and the snippet for USA at the same time.
The thing that we want is that when we are on the section USA for the brand Lucky Days to show only snippet for the USA, when we are on the section Canada for the brand Lucky Days to show only snippet for the Canada.

Here are the screenshots for that:

->hidden link
->hidden link

#1797891

You were putting another view inside of the loop when you have to use only a shortcode to get the snippet from the intermediary post type. Check this screenshot hidden link

I removed the view block from the loop. That view is not needed at all.

#1799931

My issue is resolved now. Thank you!