Skip Navigation

[Resuelto] Create a CPT with undefined structure and size

This support ticket is created hace 5 años, 1 mes. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Christian Cox hace 5 años, 1 mes.

Asistido por: Christian Cox.

Autor
Mensajes
#1360695

Hello guys,

I'm trying to configure a two separate CPTs that works together and there's 2-3 things I'm not sure how to achieve or even if it's possible at all.

The purpose is to have a general approach to registering custom designs for different type of products or creation process.

1) We would like to configure "templates" for a CPT "Design" in order to have different fields displayed according to the value of a drop-down menu. Can this be done?

For example, when we add a new entry in CPT "Design" and we choose from a drop-down menu field the value "Template #1" we have a text field and a date field, and if we choose the value "Template #2" we get a different set of fields?

2) The second layer is a CPT "Creation" that should use the data of CPT "Design" to figure out what data needs to be configured. I have attached a link to a document below to illustrate this, but a simple example would be, let's say CPT "Design" has a field "Colors" that has a value of "3". In CPT "Creation", we will want to define these colors, so we need 3 text fields. The value of "Colors" in CPT "Design" is a fixed range from 0 to 15.

3) In theory, our customers can add an infinite amount of elements (logos, images, etc.) when they are creating full-custom products. Elements are stored in the Design CPT and Creations CPTs use the Design data. Is it possible to have an unknown size for a CPT? What I mean is that we don't know in advance if the customer will use only 1 element or 28 elements. Is it possible to have "repeatable" fields that we add/remove?

The workflow would be as following...
1) Admin add new Design (CPT) and 3 sections are displayed: Design ID (autoincremented), User (from existing users) and Design Template (a drop-down menu).

2) He then selects the Design Template in a drop-down menu

[HAT (READY-MADE)]
3) 4x fields/sections appear – "Element #1" to "Element #4" have a drop-down menu to select the type. By default value is "N/A" and no other fields are displayed.
4) Admin select "Element #1" type to "Flat Embroidery"
5) 6x fields appear – Reference file url, matrix id, colorpaths, etc.
6) Admin enters value "2" in field "colorpaths" and creates the post
7) Admin add new Creation (CPT)
8) Admin assign to Creation the Design that was just created along with a Base Model
9) Creation reads that the selected Design has only 1x Element and that Element has "2" colorpaths
10) Each colorpaths must be configured with a Source and Code so 2x fields appear (E#1C#1 + E#1C#2)

or for another template...

[HAT (FULL-CUSTOM)]
3) 3x sections appear: "Product Layout" (drop-down menu), "Options" (various checkboxes and fields) and "Elements" (with a button "Add new element", maybe).
4) Admin selects the Product Layout "6-panel" which has 15x fields to configure (6 of which could be hidden conditional to a checkbox) and are displayed once the layout is set
5) After configuring the fabrics, admin can now add elements
6) For each element, he has to select a Type, a Method and the configure the corresponding fields (view excel file)
7) He saves the Design and add a new Creation
8) Based on the previously created Design, the Creation detects which fields are configurable (mostly color sources and codes) and adapt to show the proper fields.

I hope I didn't make that overly confusing.

File for reference: enlace oculto

#1360919

1) We would like to configure "templates" for a CPT "Design" in order to have different fields displayed according to the value of a drop-down menu. Can this be done?
Yes, you can set field display in wp-admin, when displaying the post, and on front-end forms depending on the selection made in other fields. You can configure conditions in wp-admin when you set up the custom field groups. In the post, you can configure conditionals with conditional HTML, and in Forms there are conditional groups so that you can display groups of custom field inputs based on other custom field selections. Some things that aren't possible are variable options for a field per post. For example, a select field can be conditionally shown or hidden based on another field selection. However, the options available in that select field are predefined, and are not variable per post based on other field selections.

2) The second layer is a CPT "Creation" that should use the data of CPT "Design" to figure out what data needs to be configured. I have attached a link to a document below to illustrate this, but a simple example would be, let's say CPT "Design" has a field "Colors" that has a value of "3". In CPT "Creation", we will want to define these colors, so we need 3 text fields.
Nothing exactly like this is available in wp-admin or in front-end Forms. When creating custom fields in wp-admin, you can set a field to be a single instance or allow multiple instances. You cannot set a fixed number of multiple instances, and that number cannot be fixed to a variable per post. If you are using Forms to create these posts on the front-end of the site, you might be able to set up something similar with some custom code, but that falls outside the scope of support we provide here in the forums.

3) In theory, our customers can add an infinite amount of elements (logos, images, etc.) when they are creating full-custom products...Is it possible to have "repeatable" fields that we add/remove?
Yes, there are two types of repetition in Types. First you have custom fields that allow multiple values. This is fairly straightforward. The User inputs a value for the field, then s/he can click "Add another item" and add another single input field. The User can add or remove items as they create or edit the post. An image input field can allow multiple values, for example, allowing your User to upload multiple images to a single field. In front-end forms, repeating input fields are all managed with the post where they are stored. Edit the post to edit the repeating fields. Again, the number of repetition iterations is not managed per post, it is inherently open-ended. In Forms, you have the ability to add custom validation using our Forms API. You could validate the number of iterations here if you'd like.

The second type of repetition is called a Repeatable Field Group, or RFG. This is a group of fields that can be repeated many times per post. For example, you might have a document RFG. That RFG might include the document title, author name, date, and a featured image. You might have a Portfolio custom post type where your Users can create multiple Document RFGs, related to one Portfolio. In front-end forms, RFGs are NOT managed with the post where they are stored. In other words, Document RFGs must be managed in a separate form from the other Portfolio post details, so keep that in mind.