Skip Navigation

[Résolu] Need Help With Many-to-Many Relationships

This support ticket is created Il y a 7 années. 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.

This topic contains 46 réponses, has 3 voix.

Last updated by Ed Il y a 7 années.

Assigned support staff: Waqas.

Auteur
Publications
#321663

Waqas
Supporter

Languages: Anglais (English )

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

I guess I am done with it. Please see hidden link - this demo page shows 2 listings:

1) All Cities -> List Cities and the listings falling under those cities
=> Uses 2 views; one for Cities, while other for Listings. The later view is based on an Intermediary Object "City-Listings-xref" (xref = cross reference, I used this term to point out the intermediary objects).

2) All City Groups -> Listings Grouped by City Groups -> City -> Listing
=> Uses 3 views; one for City Groups, second (child) for Cities (uses intermediate object), while 3rd (child of second) for Listings (uses intermediate object)

Please note, each child view has a filter on it, either for Parent Relation or for Child Relation. I have used 3 Intermediate Objects to cross reference 3 CPTs:

CPTs => City Groups, Cities, Listings
Intermediate Objects => Cities+Listing, CityGroup+City, Listing+CityGroup

This way it creates a mesh of data.

I guess observing this at your own, will help you understand the whole model. Please pardon my lack of words on describing it here.

For all of you (Ed and Christophe), please find access details to the demo site as below:

hidden link
User: ajee1985
Pass: Ajee1985

Please carefully examine CPTs in Types and Views. I have used only 1 page (as mentioned above) to display all views (2 parent/main views).

Please let me know if I am in the right direction and if it helps in this case. Thanks a lot for your patience and cooperation 🙂

#321689

Thanks for let me see.

Here is a good implementation of many to many relationship.
The demo is stronger than words.

Thanks Waqas.

#321690

Ed

Well, if you're not there, you're pretty darn close. Let me have a look at this, when I get to my office.

Thanks, Waqas!

#321695

Waqas
Supporter

Languages: Anglais (English )

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

Thanks Guys, please take your time. I am just replying to keep this thread with you and alive. Please feel free to reply as per your comfort. I will be off for the weekend and will continue on Monday.

Have a great weekend 🙂

#321822

Ed

OK. Here's what I've been able to do, using your demo (thank you SO much!).

Don't laugh at the design. That's not what I'm concerned with, at the moment. 😉

San Angelo, Texas
hidden link

San Angelo has 2 business listings tied directly to it. Angelo PC also serves cities nearby. The dummy listing only serves (chose/paid to be listed only in) San Angelo.

Christoval, Texas
hidden link

Christoval is a city near San Angelo. Angelo PC serves (chose/paid to be listed, additionally, in) Christoval.

Fort Washington, Maryland
hidden link

Fort Washington doesn't have any listings and doesn't display any that shouldn't be there.

One issue:
********************************************
Computer repair in cities near Christoval, Texas
<<img>> Angelo PC Angelo PC – San Angelo <--- right over there
********************************************

Using what I currently have, is it possible to link the text that says "San Angelo", to the actual City page?

UPDATE: I was able to link "San Angelo" to the City page, but in a really cruddy way.

UPDATE: Uhh...never mind. I'm dumb, in biblical proportions. I figured it out.

#321830

Ed

Nah...I didn't figure it out. Biblical stupidity maintained.

#322091

Ed

One thing I've noticed is that, when you go to edit a listing or a city (and maybe even a state), the editor takes FOREVER to load (and to load after updating). I think it's because each of those CPTs is tied to many other things and the lists for each city and state must be loaded, multiple times, in the editor page.

This may be the only solution, for what I want to do, but I don't know that it's the optimal solution.

#322112

Waqas
Supporter

Languages: Anglais (English )

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

Thank you for your feedback. Please consider followings regarding your recent questions:

1) is it possible to link the text that says "San Angelo", to the actual City page?
Yes, that's possible, but since all posts are under CPTs (without any categories), you won't be able to create an archive (real WP archive). But of course, you can create such a view where you can list Cities and make it looks like (design) an archive. All you will need to pass parameters (URL and/or Short Code Attribute), so your view can query (filter) the results accordingly. Intermediate objects are a great way to join the posts from different post types (having no relation infact). You can create more intermediate objects (if required). But in this very case, I think a view querying for cities and filtering based on a URL parameter would be sufficient (i.e. /cities?id=123 or /cities?name=san-angelo). And you can link to this page from wherever you want.

2) Yes of course it will slow down the thing overall. Because these are not real relationships, but are artificial joins. These are not indexed, specially if your filters are based on text-search (i.e. city name, custom field and etc). Although Views plugin has been improved for caching, but this is still a work-in-progress. And we are expecting a more reliable caching feature for Views, in the near future, which will allow the Views to return the results much faster. For now, you can try out the latest betas however, but remember to take backup of your current system before upgrade.

#322482

Ed

Waqas,
The other day, when you mentioned using taxonomies, were you suggesting that a single listing could be tagged for multiple locations or were you talking about something more ""global"?

If I were to tag a listing with "San Angelo, Texas TX" (matches the actual City name [and slug], exactly) and tag surrounding Cities, with the same tag, could I then use a filter to display listings with tags that match that tagged City, in Cities other than the original (main) City?

I think this might be a more optimal solution than the "link" CTPs.

#322487

Waqas
Supporter

Languages: Anglais (English )

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

Yes you are right. Using taxonomies gives you a flexibility to tag a single post with multiple terms. Or use a single term with multiple posts.

And of course, you can filter your content based on taxonomies, this guide may interest you around this: https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/

As a side note, Custom Taxonomies in Types offer 2 kinds of terms - Flat and Hierarchical. Both are same in terms of a taxonomy, but with a major difference:

- Flat = Can not have child terms (WP Tags are an example of this)
- Hierarchical = Can have children and grand-children (like Categories and provide more flexibility in such situations).

Using hierarchical is recommended in your case. Since these reduce data-entry efforts also. These are listed in form of a tree of checkboxes on post edit screen. While, flat taxonomies are presented as a text box, you will have to type the term and will have to select from suggested-tags (previously created). This can confuse you while attaching terms to a post or might lead to multiple-typo-errors for the same thing.

#322490

Ed

I'll be checking into this, later today. I so appreciate all your help with this.

Thank you!

#322491

Waqas
Supporter

Languages: Anglais (English )

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

Thank you, please take your time. I am just replying to keep this thread with you and alive. Please feel free to reply as per your comfort and availability.

#322594

Ed

Oh, boy! It works!

I was able to clean up all of those extra post types and views. The site is happy, now.

I wasn't able to use "San Angelo, Texas TX" as a taxonomy (like I thought), but that ended up not mattering.

I have two "Service Regions" (so far). I tied the listings and the cities to specific Service Regions (San Angelo 1 and San Angelo 2).

I also added "Regional Listing" as a taxonomy and added that to specific listings.

I use both taxonomies to filter listings not belonging to both.

So far, it seems to be working perfectly.

Thank you ALL so much for your help with this. (it was a pretty big deal)

#322675

Ed

OK...I got excited maybe a bit too soon.

Listings that are designated "Regional" are showing up in cities that they shouldn't. I think I might need help with the filter(s).

#322678

Ed

Nah...I figured it out.

I didn't mark this as resolved. I think it can be marked that way.