Skip Navigation

[Resolved] Creating a relationship with existing data to be reused across multiple posts

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

Problem: I would like to set up Properties (a CPT) so that they can be associated with Amenities. What is the best way to do this so the Amenities can be reused across multiple Properties?

Solution: Use a custom field on your Properties custom post type that allows your users to select multiple Amenities using checkboxes. The same checkboxes will be available on all Property posts, so you can reuse the same options but make different selections. Use unique numeric values for each option, and save "0" when nothing is checked.

To display the selected Amenities on a Property post on the front-end, use conditionals to determine whether an option was checked:

[wpv-conditional if="( $(wpcf-amenities-list) eq '1' )"]
  Garage
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-amenities-list) eq '2' )"]
  BBQ
[/wpv-conditional]

Relevant Documentation: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 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)

This topic contains 4 replies, has 2 voices.

Last updated by fredB-4 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#589866
Amenities on Property.jpg
Amenities.jpg
Amenities to Property.jpg

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

#589938
clean-8888-wp-admin-admin.php-page=wpcf-edit.png

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.

#590456

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?

#590972

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.

#591227

Thank you