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
#320462

Ed

I have states and cities. I also have listings. I have listings that belong to one city and listings that belong to multiple cities.

I want to display the single-city listings only on THAT particular city. I want to display listings that belong to multiple cities ONLY in those cities they belong to.

Let's say "Listing A" belongs only to Dallas, Texas and "Listing B" belongs to Dallas, Texas and a number of cities surrounding Dallas.

I want "Listing A" to only show up in Dallas and "Listing B" to show up in Dallas and (only) the other cities it belongs to (so neither should show up in Birmingham, Alabama).

I want to do the same thing for listings that belong to multiple states.

I've read the documentation, but nothing I've seen really matches what I want to do (so it's confusing). If you give me some privacy on the next post, I'll post the URL and my credentials.

PS: I also created CPT "Multiple City Area" as an intermediary post type. No, I don't know if that was correct or not. Like I said, I was confused.

#320493

Hello,

you were good in the way it is a many to many relationship.
i think you folowed this documention :
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/
which is the good way to follow.

In your case, bands is your listings.
(band can be in one or many events same your listings can be in one or many cities)

Events are your cities, and appearances will be your intermediary post "Multiple City Area".

Be sure you set "Multiple City Area" as child of cities and listings.
For make a new connection, create a new 'Multiple City Area' post and select in the bottom of the page the correct listing and city.
You can create as many "connection" (post) as you need

For display them, you should'nt have problem by folowing the documentation.

create view that loads all "Multiple City Area" from city
in view loop, display the parent listing of "Multiple City Area".

Hope it helps,
Regards

#320518

Waqas
Supporter

Languages: Anglais (English )

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

@ed: If solution provided by 'Christophe Lopez' doesn't help (which I think you should give a try to), please find the private area enabled for your next reply.

#320524

Ed

I'm certain I'm doing something wrong.

This: [wpv-view name='MultiCity Listings' id='$parent']
Will not display the multi-city listings.

This: [wpv-view name='MultiCity Listings']
Displays the multi-city listings in all cities.

Are you certain that "Multiple City Area" should be a child of cities and listings and not the other way around?

#320527

Ed

Waqas,
Thank you, but the secure form wasn't displayed for my reply. Can we give that another shot, so I can send my credentials?

Also, this should not be marked as "resolved".

#320532

Waqas
Supporter

Languages: Anglais (English )

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

I guess something went wrong, however, I have just enabled the private details area again.

#320809

Waqas
Supporter

Languages: Anglais (English )

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

Thank you for providing the access. Please allow me some time to work on this, I will update you as soon as I find a solution.

#320813

Ed

Thanks, Waqas. I appreciate your help.

You as well, Christophe.

#321251

Waqas
Supporter

Languages: Anglais (English )

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

I have just observed your setup in your website. I tried replicating the same scenario on my local host and found that the solution prescribed by Christophe is a good-go.

I will copy the words below:

"...Be sure you set "Multiple City Area" as child of cities and listings.
For make a new connection, create a new 'Multiple City Area' post and select in the bottom of the page the correct listing and city.
You can create as many "connection" (post) as you need

For display them, you should'nt have problem by folowing the documentation.

create view that loads all "Multiple City Area" from city
in view loop, display the parent listing of "Multiple City Area"..."

And your question "Are you certain that "Multiple City Area" should be a child of cities and listings and not the other way around?"

Yes, that's correct, that "Multiple City Area" should be the child of Cities and Listings. Since, it's an intermediary object, changing it's relation will change the way it is connected. And of course the further way explained about creating a view to present the listings.

I hope this will help you fixing this very issue. Please let me know if I can help you with anything related, thanks.

#321261

Ed

Thank you, Waqas.

I've been "messing" with this, on my own. I still can't wrap my head around the intermediary being a child of cities, because then each "Multiple City Area" can only have one parent city, when the object is for it to be attached to multiple cities (and possibly multiple listings).

I'll attempt this solution, later this morning. I'll let you know how it goes.

#321273

Waqas
Supporter

Languages: Anglais (English )

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

Sure please take your time. I am just replying to keep this thread alive and with you. Please feel free to reply when possible, thanks.

#321274

Ed

Yeah, that didn't work. I tried that, when it was first suggested. Having Multiple City Areas as children of Cities and Listings offers me no way to add multiple Cities to a Multiple City Area and adding more than one Multiple City Area to a Listing just doesn't even make sense (to me).

Maybe I need more help with the concept, than with the coding.

#321275

Waqas
Supporter

Languages: Anglais (English )

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

Alright, I will create a demo site from scratch and will implement this thing. I will share with you all the details. So you can compare and make adjustments.

Please allow me some time, I will get back to you soon, thanks.

#321281

Ed

Here's how I see things working (in my head)...

Cities belong to States.
Cities also belong to Multiple City Areas.
Listings can belong to single Cities (mostly), multiple Cities (by attaching them to a single Multiple City Area or multiple Multiple City Areas), and/or States.

When viewing a single State, only listings that are "elevated" to State level will be shown.
When viewing a single City, listings belonging to that City will be shown, as well as listings that belong to a Multiple City Area which contains that City and listings that are "elevated" to State level (for that city's parent State).

Having multiple views in order to accomplish this is expected.

Again, you don't know how much I appreciate your help with this.

#321316
img.jpg

Hello,

"Multiple City Area" is the intermediary post. It is used as a link between cities and listing.
"Multiple City Area" will be child of one listing and one city at a time.
But you can create as many "Multiple City Area" (link) as you need.

As you can see in img attached
if you want show all listing from city 1
In a city page, display all her multiple city area ( here n°1, n°2, n°3)
then display name of parent of multiple city area of type listing ( lst1, lst2, lst3)

if you want show all listing from city 2
In a city page, display all her multiple city area ( here n°4, n°5)
then display name of parent of multiple city area of type listing ( lst1, lst3)

i named the intermediary post Multiple City Area to follow your first post. But it can be less confusing to name whatever you want.

Hope it was more clear

regards