Skip Navigation

[Resolved] How do I insert the State and City fields?

This support ticket is created 3 years, 10 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by Shane 3 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#1983329

Tell us what you are trying to do?
I have States and Cities set up in a parent and child relationship. I have added several states and several cities. I have been able to get things to work using a view with the search function. I have not been able to get the State and City selectors to work with Forms and Pages.

I have 2 questions about how to use these fields.

1. How do I correctly insert the State and City fields on the add post form? When a user is adding a post on the front end using a CRED form, I want to be able to have them select the state and then select a city in that state. Meaning that only cities that are ancestors of the state will dynamically display in the City dropdown list.

2. How do I display the State and City (for a Property) on a page?

What is the link to your site?
hidden link

#1983933

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kegan,

Thank you for getting in touch.
1. How do I correctly insert the State and City fields on the add post form? When a user is adding a post on the front end using a CRED form, I want to be able to have them select the state and then select a city in that state. Meaning that only cities that are ancestors of the state will dynamically display in the City dropdown list.

I'm assuming here that your Property is only related to City correct? if so then you will only be able to add the City dropdown to your Properties form.

To add the dropdown lists to your form, you will need to go to the Toolset -> Forms and edit the form that you want to add the relationship field to. Then under Relationships on the Edit form page, you should see the field for your Post Relationship.

If you are not seeing this please let me know. It should also be noted that the field will only appear on the Child post type in the relationship.

2. How do I display the State and City (for a Property) on a page?

In order to advise on this one I will need to understand the relationship between State,City and Property. Can you send me a screenshot of the Relationship page at Toolset->Relationship, ensuring that i'm able to see the 3 relationships listed above.

Thanks,
Shane

#1983973
Relationships - 2021-03-12_104849.jpg

First, let me clarify that I started with the defaults for the 'Real Estate Reference Site' that I imported into my WordPress Installation. However, am trying to learn how to use Toolset and so am making some changes.

One of the changes is adding the State and City fields to the add property page.

The other change is that I want to display the State and City on a page and not just the address field as it is in the default 'Real Estate Reference Site' installation.

I'm assuming here that your Property is only related to City correct? if so then you will only be able to add the City dropdown to your Properties form.

To add the dropdown lists to your form, you will need to go to the Toolset -> Forms and edit the form that you want to add the relationship field to. Then under Relationships on the Edit form page, you should see the field for your Post Relationship.

If you are not seeing this please let me know. It should also be noted that the field will only appear on the Child post type in the relationship.

It appears to me that Properties are related to both States and Cities. So I would need to add both the State and the City dropdowns.

I added the 'Cities Properties' to the 'Submit property' form. It appears to only allow me to choose a city. I want to be able to choose the state first and then have only the cities in that state be available to choose from. By adding the 'Cities Properties' field to the form, it appears to display all cities from all states.

So to answer your question: I believe that my Property is related to both a State and a City. So I want to add both dropdowns to my form.

In order to advise on this one I will need to understand the relationship between State,City and Property. Can you send me a screenshot of the Relationship page at Toolset->Relationship, ensuring that i'm able to see the 3 relationships listed above.

It is the default relationships as set up in the 'Real Estate Reference Site'. I have included a screen shot.

#1984003

.

#1984231

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2021-03-12 at 2.37.03 PM.png
Screenshot 2021-03-12 at 2.33.53 PM.png

Hi Kegan,

Now I understand the full context.

So to answer your question: I believe that my Property is related to both a State and a City. So I want to add both dropdowns to my form.

You wont be able to select the state as the state would've have already been related to City that is being selected on the property. What this means is that a City would've already been assigned to a state and once you select a city for your Property then it would automatically be related to a state through the city post type.

Now to display the City on the property you can use a single line field and then select "Standard Field" and for the Post Source you will select "Parent:City" and finally for the Post Field select Post Title. See Screenshot.

The parent State will be a little more tricky as for this you will need to create a view on the Same Property content template. This view you will set to list out the Cities. Once you've created the view Add a single field and follow the procedures above, however for the Post Source you will select "Parent:State"

Next you will need to add a query filter for the Post Relationship of the view. You will set the Post Relationship filter to "in the Cities Properties Relationship". See Screenshot.

If you are not seeing these options, you will need to use the block Navigator tool in the Top left hand side of the editor and Select the view.
Once you've done these steps correctly you should now see the City and the state being listed out on the template.

Ofcourse some amount of work will be needed to format the information on the page, however this is how you will get the information to be listed out on the page.

Please let me know if this helps.
Thanks,
Shane

#1985029

You wont be able to select the state as the state would've have already been related to City that is being selected on the property. What this means is that a City would've already been assigned to a state and once you select a city for your Property then it would automatically be related to a state through the city post type.

I think I understand what you are saying. However, when a person is on the Add property page, I want them to be able to select the state first before choosing the city like it is in the Find a property page:
hidden link

The main reason for this is that when the state is the first item to select it would only give them (at most) 50 items to choose from first and then once they selected the state they would only get cities in the dropdown that are in that state. If they have to choose the city without choosing the state first then there could be thousands of cities they would have to go through to find the city they need. Plus if the same city name is in more than one state: How would they know which state they are selecting?

#1987925

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kegan,

I understand what you are trying to do, however the main issue now is that we don't have a dependency dropdown for this.

What this means is that if you relate the property to a State, the city dropdown won't automatically filter for that State's cities. So I understand the concern about the user not knowing which State their selected city will belong to.

What I know is there has been discussions amongst the team to improve this functionality, however at the moment we do not have a solution on hand.

If you need to State dropdown then you can just create a new relationship in Toolset -> Relationships between the Properties and States and then go to your form on the backend and add the State relationship field to the form.

Please let me know if this helps.
Thanks,
Shane

#1988117

So there is the ability to have the dependency when doing a search but that same dependency does not work when adding a property? Why does it work in one spot but not in another?

#1989637

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kegan,

So there is the ability to have the dependency when doing a search but that same dependency does not work when adding a property? Why does it work in one spot but not in another?

That is correct. I spoke with our team lead to bring this to our developers attention so that they can add this feature or take a look to see how best they can improve this one.

Currently we do not have a workaround for this one but I understand the concern regarding the duplicate city names belonging to multiple states and have shared this concern with our Team leader.

Thanks,
Shane