Skip Navigation

[Resolved] Drop down menus for Countries and Cities in dependency

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a Form that creates new posts. I would like to be able to select the parent and grandparent posts in the Form.

Solution: Toolset only offers the ability to select a parent post in Forms. You could use generic fields if you want to accomplish this with some custom code, but it's not recommended.

This support ticket is created 6 years 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1151962
Sezioni-Paese.png

Tell us what you are trying to do?
I have created "Profili" Custom Post Type
First, I need to have that one user can create only one post in "Profili", so this CPT is an extension about User Profile
Second, I have created three CPT: Countries, Regions and Cities. I have created the Relationship one to many between Countries and Regions, Regions and Cities, Cities and Profili.
Now, in Toolset Form, about Profili CPT, I need to have the down drop selector to select Country, Region and City for the Single Profili, but now I can select only the City.
It is because the relationship with CPT Profili is only with the CPT Cities? To have what I need, it need to create other relationship between Countries and Profili, Regions and Profili?

In specific I need to have what is in the attached image. When I select a Country, I can Select only one Region related the Country, and after the Region selection I can select the City related the Region.

Is there any documentation that you are following?
I don't know, for now I have following this guide https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/

Is there a similar example that we can see?
So, this is an Hot Sex Dating site, this is the link hidden link

What is the link to your site?
hidden link

#1152646

Now, in Toolset Form, about Profili CPT, I need to have the down drop selector to select Country, Region and City for the Single Profili, but now I can select only the City. It is because the relationship with CPT Profili is only with the CPT Cities?
Yes, that is correct. Since Profili is not a child of Country or Region, Forms does not allow you to select those post types.

To have what I need, it need to create other relationship between Countries and Profili, Regions and Profili?
No, that could lead to problems where relationships are out of sync. There isn't an easy way to have exactly what you want in Toolset, because Forms are not designed to provide multiple levels of hierarchy like this. In general, Forms allow you to select one Parent post for a child post, but no grandparents or great-grandparents.l

We do offer the ability to create generic fields in a Form, so you could create your own Country and Region fields and allow your Users to select the Country and Region from the generic fields. You can use Forms Conditional Groups to show and hide fields based on the selections in other fields:
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://wp-types.com/documentation/user-guides/conditional-display-for-form-inputs/

Then you can use the Forms API and the Post Relationships API to associate the correct posts with PHP:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

I'm available to assist with any code that uses Toolset APIs.

#1154976

Ok, and so, from the CPT Profili Form an user can add (publish) the new his own City into the CPT City, or can he select only the Cities that I have published before?

#1154977

Also I need that every user can create only one post in CPT Profili.
What should I do to do that?

#1155578

Ok, and so, from the CPT Profili Form an user can add (publish) the new his own City into the CPT City, or can he select only the Cities that I have published before?
In the Profili Form you must choose from existing City posts. You cannot publish a City post directly from the Profili Form. You could display two forms on the same page - one to create Cities and another to edit Profili. Then after creating City post, refresh the page to show the updated list of Cities in the Profili Form.

Also I need that every user can create only one post in CPT Profili.
What should I do to do that?

The documentation here explains how to set this up for Contractors: https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/
You will create a View of Profili posts, where the author is the current User. If no results are found, you will display the Form to create a Profili post. If a result is found, you will hide the create Profili Form.

#1155683

So, to semplify my work I'm thinking to adopt the following logic, because to adding all cities of the nation is an hard work. Tell me if the logic can work fine.
I will delete the CPT City.
I will create a CPT Province, that it will be son of CPT Region and parent of CPT Profili, with Relationship.
I will create a Map Custom Field called City.
Than the user can select the "Provincia" and write the name of the City in Maps.

In the frontend it will appear the name of the City with a little map and his marker, the name with link of "Provincia" to open the Post of CPT Province with the Map and the marker of all memeber that have select the same Provincia related to the city, and after the map a section where are displayed all Profili with the same Provincia. Here it will be a search form where insert the name of the city to zoom the map about the city, and display the Profili with the same City.
The same will be for Region and for Country.

So, in the Profili CPT, when a user select the "Provincia", in front end can I display the "Region" parent of "Provincia"?

#1155729

Than the user can select the "Provincia" and write the name of the City in Maps.
Let's say Provincia are like states in the USA, as a simple example. If you do this, there is nothing to prevent the User from writing a full address like "123 7 Ave N, New York, NY" instead of just "New York" in the address field. Also there is nothing to prevent the User from selecting "California" as Provincia(State), then writing "New York, NY" in the address field. It will most likely lead to corrupted data, where New York City Profiles show up in California, unless you implement a considerable amount of custom code or approval workflows.

So, in the Profili CPT, when a user select the "Provincia", in front end can I display the "Region" parent of "Provincia"?
Yes, you can see more information about displaying related post information here: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/

#1162516
Funkman733   incontrAmici.png

Hi, I'm trying to display the grandparents, but I don't why, I cannot display nothing...
So I need to display that:
"Sono di [City, parent], in Provincia di [Provincia, grandparent], Regione [Regione, grandgrandparent] ([Paese, grandgrandgrandparent]).

I have created a Content Model for every grand-parent.

I have created a View, where I have inserted into the loop all I need

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>		
        Sono di [wpv-post-link item='@citta-profilo.parent'], [wpv-post-body item="@provincia-citta.parent" view_template="mostra-provincia"], [wpv-post-body item="@regione-provincia.parent" view_template="mostra-regione"] ([wpv-post-body item="@paese-regione.parent" view_template="mostra-stato"])            
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

In the template I have inserted the view shortcode and I have that (see the attached image)

what is the issue?