Skip Navigation

[Resolved] Custom Repeatable field with suggestion

This support ticket is created 3 years, 2 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 3 replies, has 2 voices.

Last updated by Christian Cox 3 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#2140781

Hi there,
We are using "Toolset Types" for an underdevelopment website.

I am wondering what's the best way to create a custom field with predictions?

For example, We have 2 different post types named Missing Products and Unique Codes. We want to create a field (with Allow Multiple instances) for Unique Codes post type. And this custom field suggests missing product when an admin starts typing.

Any kind of help will be appreciated.

#2141207

Hello, none of Toolset's custom fields work exactly like this, but it sounds like you could accomplish something similar with a many-to-many (M2M) post relationship between Missing Products and Unique Codes. When creating or editing a Unique Code post, admins will see a post relationships panel where they can choose Missing Products to connect to the current Unique Code. There is a text input field where the admin can start typing the name of a Missing Product, and the system will provide matching results. Then the admin can select one of the matching Missing Product posts from the list of suggestions. This will create a connection between the two posts in an M2M post relationship. Since it's an M2M relationship, the admin can connect multiple Missing Products to each Unique Code post, and vice versa.

Will this work for your needs?

#2141525

Hi,
Thanks for your reply and assistance.

Yeah, I understand that. But the issue of having relationship is that we can't export/import related products. For example, if Unique codes and Missing Products have Many to Many relation. Then how can I export/import unique codes with related missing products?

It's listed that "WP All Export" plugin can export the relationship for toolset types but I am not sure about the import too.

#2143119

For example, if Unique codes and Missing Products have Many to Many relation. Then how can I export/import unique codes with related missing products?
The standard post export process built-in to WordPress at wp-admin > Tools > Export will include related post information automatically in the child and intermediary post types, encoded as special custom field values. If you are unsure which post type is the child and which is the parent, you can find that information by editing the relationship in Toolset > Post Relationships. Export those posts and you'll see relationship information added as special custom fields.

The format for the custom field slug name is "_toolset_associations_{relationship-slug}", where {relationship-slug} is the slug of the M2M relationship. An example showing this special custom field added to the Events post type in a M2M relationship "Band-Event", where Event is the child post type:

		<wp:postmeta>
		<wp:meta_key><![CDATA[_toolset_associations_band-event]]></wp:meta_key>
		<wp:meta_value><![CDATA[{!{<em><u>hidden link</u></em>}!} + {!{<em><u>hidden link</u></em>}!}]]></wp:meta_value>
		</wp:postmeta>

Before importing those posts in another site, you should set up the custom post types, custom fields, and post relationships in the new site to match the post types, custom fields, and post relationships in the old site. You can use the Toolset Export / Import tools to do this automatically. The export feature at Toolset > Export / Import > Types tab will help you export Types structures for importing in another site. Then the post types, custom fields, and relationships will be set up and ready for importing posts in the new site.

When you import these exported posts in another site using the WordPress Import tool (wp-admin > Tools > Import), the specially coded custom field values will be registered for automatic import in Toolset > Export / Import > Relationships tab. You can run the automated process to convert those custom field values into true Toolset relationships. I suggest exporting and importing the intermediary post type as well as the two other post types in the M2M relationship. This is required if there are custom fields associated with the relationship/intermediary post type.

I'm not aware of any 3rd-party tools that have built-in support for exporting post relationship information in CSV format. The WordPress export tool produces an XML-like document instead of CSV, and that is perfect for importing in another WordPress site. The WP All Export plugin does allow you to implement custom code snippets as formulae for populating custom field values, so it is possible to add custom field(s) with related post information. I've explained how this might work in other tickets, with code examples:
https://toolset.com/forums/topic/export-custom-post-type-data-to-csv/
https://toolset.com/forums/topic/export-custom-post-type-data-and-related-repeatable-field-group-data/
If you're not really comfortable with custom code, I suggest using the built-in WordPress export and import tools, since the post relationship information will be included and processed automatically without any need for extra custom code.