Skip Navigation

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

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

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 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

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

Last updated by Ed Il y a 8 années et 6 mois.

Assisted by: Waqas.



I honestly don't believe we're on the same page.

I don't ever want to display a "Multiple City Area". I only want to display/view Cities, States, and Listings. The listings must be attached to a City. Listings can also be attached to a State. Listings can also be attached to a single Multiple City Area or multiple Multiple City Areas, without the Multiple City Area ever being displayed.


Yes, sorry i said display "Multiple City Area", i should said "call" instead. You need to call them because they are your link between city and listing.

You should also make new post type as intermediary post between listing and states. (wihich will be child of listing and states)

I understand your confuseness as it not a easy concept at first glance.

I can try to explain you further. But im sure demo site of Waqas will be a better help.



I think my problem with the concept is that I want a "Dallas" listing to display when viewing the City, "Dallas", and I also want to display the listings in a number of cities surrounding Dallas, which belong to the "Dallas Area" intermediary post (which is attached to multiple cities).

I don't want, as intermediary posts:
Dallas Area 1 (with one city)
Dallas Area 2 (with one city)
Dallas Area 3 (with one city)
(one for each city I want to include in the group)


Sorry im confused too ...

Can you look at theimg attached and tell me if it is what you try to achieve



Yes, that looks about right.

We'll have "CityGroups" and (eventually) "StateGroups" which will contain multiple cities and multiple states, respectively.

Optimally, a listing must belong to a city, but could also belong to multiple cities (and states) or multiple CityGroups or StateGroups.



Would it be easier to create different post types for each listing level (City Listing, Multi-City Listing, State Listing, Multi-State Listing)? I had actually already started doing that, but reversed course.


Ok, thank you for your patience, but its quiet complex as there will be a lot of relationship between many post type.
i think every thing must be really clear first before to go deep in a wrong way.

Lets say
Dallas belongs to Texas
And "listing 1" belongs directly to Texas
Do you want to see listing 1 in Dallas view ?



Yes, but it could/would be displayed in a separate view, below the more local (City) listings and the listings belonging to the "Dallas Area" CityGroup.

So it would be displayed as:
City listings (if any)
CityGroup listings (if any)
State listings (if any)(optional)
StateGroup listings (if any)(optional)



Side note: All the listings above City level will be premium listings and I want to keep everything as automated as it can be.



As for the StateGroups, I might want to add one called "Desert Southwest 1" and add the States "Arizona" and "New Mexico". Listings belonging to that StateGroup would be displayed when viewing either of those states (under StateGroup listings) or when viewing Cities in those States.

I might later want to add a StateGroup called "Desert Southwest 2" and add the States "Arizona", "New Mexico", "Texas", and "California", with the same requirements as "Desert Southwest 1".

I don't want to display any listing twice on one page.

Since each listing must belong to a City (before it can belong to anything above it), I only want it displayed at it's lowest level. If you're viewing the City of "Dallas", which resides in the State of "Texas", and a Listing belongs to "Dallas" AND "Dallas Area 1" AND "Texas" AND "Desert Southwest 2", I want it to be listed under "City Listings" only.

If you're viewing the State of "Dallas", which resides in the State of "Texas", and a Listing belongs to "El Paso" AND "Texas" AND "Desert Southwest 2", I want it to be listed under "State Listings" only.

Again, the whole StateGroups thing is optional (but I really want it).



And, Waqas, I'm not trying to move the goal post on you. If we can get the first part figured out, I think I can take care of the second part.



Languages: Anglais (English )

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

Sorry for being late to the party. After reading all the messages, I just wanted to ask about the use of taxonomies.

@ed, do you think this can be solved with the hierarchical taxonomies? Like categories and sub-categories.

For example, city taxonomy:

- Texas
-- Texas Area 1
-- Texas Area 2

So a listing can be attached with any of these. And you can query (using Views) for a particular term or for child terms. There can be separate taxonomies for States but I guess a hierarchical taxonomy will hold the Parent -> Child -> Grand Child relation, all the way down (up to the city area).

Actually what I understood so far is:

- Show all computer repair listings in Texas (including/excluding suburbs or child terms)
- Texas suburbs (or nearby areas), a.k.a. related listings: query for child terms

Because I think, a many-to-many relation may not be suitable in this particular scenario. I may be wrong, please correct me. Awaiting your reply, thanks.



I've already got 13000 cities, as custom posts. I don't think switching to taxonomies is in my future.



Languages: Anglais (English )

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

Alright, that makes sense. I will get back to you soon.



Thanks, Waqas. I appreciate it.

If I could just figure out how to display Listings, that belong to CityGroups, which contain Cities other than the specific City the Listing resides in, we'd be in good shape.

Grandparents are the CityGroups
Parents are the Cities
Children are the Listings
A City in a CityGroup, other than the parent City, would be an aunt/uncle
The Listings in those other Cities, which reside in the CityGroup, would be nieces/nephews of the current City

I need to figure out how to display Listings as nieces/nephews of the current City

You're viewing the City of "Fort Worth TX". You'll see Listings that belong to "Fort Worth". Below those listings, you would see Listings that belong specifically to the City of "Dallas", but also belong to the "Dallas Area 1" CityGroup, which contains the City of "Fort Worth".

Simplified: I want to give Listings more than one parent of the same post type (City).

...I think.

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