I am building a property rental website.
I have Property as a post. Related to this is amenities.
Example of amenity
Garage
BBQ
Full Kitchen
So some of the property posts have some of the amenities. how do I set up the relationship?
If I create Amenities as a Child of Properties. I have to create the amenities for every property.
I would like to select and add it to the property from a pre-setup post called amenities, as each amenity also has an icon attached to it.
Please help! 🙂
What is the link to your site?
hidden link
Hi, I see that you have a post type called Amenities, as well as a custom field group called Amenities. I don't think the custom post type is necessary right now. I would use the custom field group instead of the custom post type. The reason is that you want to be able to reuse Amenities in multiple Properties, and you might want to be able to search and filter Properties based on specific Amenities. If you use a parent / child relationship to add Amenities to a Property, then those Amenities cannot be reused, and are specific to that Property only and cannot be used as filters. Instead, you should use the Amenities field group.
Edit your Amenities post field group so that these fields are available in Property posts, not in Amenities posts. Then add each Amenity as an option in a group of checkboxes. For best results, use unique numeric values for each option (like Garage = 1, BBQ = 2, etc) and save 0 to the database when nothing is selected. See the attached screenshot for an example.
Then, when you edit any Property you will see the Amenities checkboxes available and you can select the relevant Amenities for this Property. Then in your Property page or template, you can use conditional HTML to determine which Amenities should be visible. Quick example:
[wpv-conditional if="( $(wpcf-amenities-list) eq '1' )"]
Garage
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-amenities-list) eq '2' )"]
BBQ
[/wpv-conditional]
More information about conditional HTML here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
Let me know if you have additional questions about this approach.
Hi,
Thank you for that option. There are 92 items.
I would like to use the checkbox option, but to populate 92 checkboxes via a GUI, is going to take too long.
Is there a MySQL way maybe or any other way?
Toolset offers an export / import tool that you could use for this.
- Create your checkboxes field and add several options manually. Test on the front-end of your site to be sure the fields work as expected in display and in search filters
- Export all your Types data using Toolset > Import / Export > Types
- Expand the zip file and edit the XML file
- Copy a node that represents one of the checkbox field options and use it as a template to generate nodes for each of your desired options. The existing field names have long unique strings. Your new items can simply use sequential digits instead of the long unique string.
- Insert the additional options in the XML document after the existing options.
- Resave the XML document and create a new zip package with the previous PHP file, then import the new zip package at Types > Import / Export > Types to overwrite the existing options.