Skip Navigation

[Resolved] Custom fields with data of other post type

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

Problem: I would like to populate custom fields in CPT A with values from CPT B.

Solution: There are two main options here:
- Use Import / Export to export an XML file of a few options, then add your options and re-import.
- Use Parent / Child relationships.

Relevant Documentation:
https://toolset.com/documentation/user-guides/types-custom-fields-conditional-display/
https://toolset.com/documentation/user-guides/creating-post-type-relationships/

This support ticket is created 6 years, 9 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
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 Eric De Paep 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#548465

Hi,

I am trying to build a car dealer website so I created a custom post type for Used Cars. I need to add (among others) "Make" and "Model" custom fields. As there are a lot of makes and models, it would not be convenient to add all these as options of a "select" field type. I'd like to create 2 additional post types, one for Makes and another for Models and being able to display the values of these 2 custom post types in a "select" field type of the Used Cars post type. This way my client could use the Makes and Models custom post types to manage makes and models and select the values entered in these 2 custom post types from the Used Cars UI. Is this possible? If not, what would be the best practise?

Thanks.

Best regards

#548517

Hi, this can be accomplished with custom fields, as you have mentioned, or with custom post types. Let me explain these options a bit so you will know what you're getting into either way.

If you use custom fields (2 selects in the Car admin, one for Make and one for Model) then you have the option to make these data-dependent field groups. This means that you can display a Make custom field first in the admin area, and when you select a Make the next select field appears showing all the different Models in that Make. This makes it a bit easier to manage in the Car admin area, because you don't have to search through lots of Models that aren't related to the chosen Make. On the other hand it takes a bit more time to set up in the beginning, because you have to set up all the conditional logic that determines which fields to show and hide when you select a Make. Here's some more information about conditional fields: https://toolset.com/documentation/user-guides/types-custom-fields-conditional-display/

If you use custom post types for Make and Model, then to manage those relationships from the Car admin area you must set up parent and child relationships. You can choose to set up a 3-level hierarchy (Make > Model > Car), where Models must be children of Makes and Cars must be children of Models. In the admin area for Cars, you would use a typeahead field to select only the parent Model. In the Model admin area, you would similarly select a Make. This is how the hierarchy is enforced - you choose a single parent for each child post. Or, you can create child posts directly from the parent post admin. So when you create a Model, you can begin adding Cars directly from the Model admin area. One drawback to this approach is that when you select a Model from the Car admin page, you don't have the ability to filter Models by Make. You must choose from all Models. On the other hand, you save time up front because you do not need to add conditional logic to your post fields. More information about parent / child relationships here: https://toolset.com/documentation/user-guides/creating-post-type-relationships/

If a 3-level hierarchy isn't what you want, you can create a two-level hierarchy. Make and Model would both be parents of Car. Then from the car admin area, you would have two typeahead fields - one for Make and one for Model. There would not necessarily be a relationship between Make and Model. Again, you would have to select from all Models since Make and Model are no longer connected by a parent / child relationship.

Let me know your thoughts, or if you have additional questions about this.

#548711

Hi,

Thank you for your early reply. If I understand well, when using the custom fields solution, I still have to add all makes as an option of the Make select field in the Toolset UI. The conditional display only manages which models will appear when a Make is selected. This doesn't bring a solution for the Makes and Models management outside the Toolset UI.

As for the second solution, I'm a bit confused about it. I understand how the hierarchy works but it is a pitty you can't filter models by Make. By the way, how do I get a typeahead field? Is this a single line field?

I wonder if it would not be possible to use taxonomies and categories to manage Makes and Models?

Thanks.

Best regards.

#549226
Screen Shot 2017-07-16 at 10.33.37 AM.png

If I understand well, when using the custom fields solution, I still have to add all makes as an option of the Make select field in the Toolset UI.
You can import options for the custom select field if you don't want to manage them in the Toolset UI. First, create one or two options manually in the Toolset UI. Then export your custom field by going to Toolset > Import / Export. You will download an XML file that you can open and modify. If you're comfortable modifying XML files, this is one method of field option management outside the UI.

By the way, how do I get a typeahead field? Is this a single line field?
You mean is a typeahead offered as a custom field type? No, there isn't a typeahead custom field available, and single line fields don't offer this feature. When you set up a parent / child relationship, Types automatically adds a parent typeahead field to the child post editor. There's nothing special you need to do to enable this field other than define the parent / child relationship between post types.

I wonder if it would not be possible to use taxonomies and categories to manage Makes and Models?
You could use categories to manage Makes and Models. A hierarchical taxonomy system might work. You'll have to use the standard WordPress category interface (a set of hierarchical checkboxes showing all the possible categories in a single interface) in the wp-admin area. So this doesn't really help you streamline the management of Makes and Models, but it does provide a typeahead interface for category management. Image attached for reference.

#549466

Hi,
Thanks for your help. I now have a good view of the different possibilities. Nevertheless I think it would be a great addition to Toolset to have the possibility to define the options of a custom select field by adding posts to another post type or to populate a field with a shortcode. I mean, that is how you expect a car dealer site to work. You add a Model or a Make in the Make or Modem admin and, when you add a car, you can select this Model or Make from the select field dropdown.
Cheers

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.