Skip Navigation

[Résolu] Display the values ​​of a CPT in a data entry form drop-down list.

This support ticket is created Il y a 1 mois et 1 semaine. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Ce sujet contient 7 réponses, a 2 voix.

Dernière mise à jour par Minesh Il y a 1 mois.

Assisté par: Minesh.

Auteur
Publications
#2778155

Tell us what you are trying to do?
I have created a CPT called dog breeds. Now the next step is to create another CPT called dogs.
Then I will create a one-to-many relationship (a dog can only be one breed but a breed can have many dogs).
Would it be possible to add a drop down list to show the CPT breed list in the frontend form?

Is there any documentation that you are following?
No

Is there a similar example that we can see?
No

What is the link to your site?
lien caché

#2778158

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

When you have one-to-many post relationship and if you create a frontend form for the child post type, then if will offer you the parent field as dropdown so that you can connect the child item you are creating with your desired parent.

More info:
- https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/#creating-forms-with-selectors-for-the-parent-post

#2778218

Hello Minesh,

I followed the instructions and I think I have succeeded.

But in the drop-down list only some elements are shown and not all of them, Is there a possibility to show all the elements in the drop-down list?

I would like to know if I am doing things right, so I have another question. When the user adds a dog through the frontend form, the data is stored in the dogs CPT, but what about the breed field that is selected from another CPT through a drop-down?

Do I need to add another field inside the CPT dogs to be able to store the value of the CPT breed that is selected from the drop-down list?

Thank you very much in advance for your answer!

Best regards,

#2778269

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Please check the following Doc that shows important information about how psot-relationship works:
- https://toolset.com/course-lesson/what-are-post-relationships-and-how-they-work/
- https://toolset.com/glossary/post-relationships

When you select the parent post in your child form - the parent post should be automatically connected when you edit your edit child post in backend under the post-relationship box.

You can follow any of the course we offer that will help you to understand how all these features works:
- https://toolset.com/course/

#2778319
screenshot.jpg

Thank you very much for your reply!

I will take a look at the Toolset documentation, especially the courses.

At the moment I only have one question left to resolve, in the drop-down list only some elements are shown and not all.

Is there a possibility to show all the elements of the CPT in the drop-down list?

All the best,

#2778519

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Well - the parent field is a select2 field so only limited options are displayed by default. For more option you should try to search in the text box and it will offer you the found options.

If you do not want to use that, then you can switch to "Expert Mode" and to the parent field what if you try to add the attribute use_select2="never":

For example:

[cred_field field="@relationship-slug.parent" use_select2="never" class="form-control" output="bootstrap"]
#2778527

Hi Minesh,

It seems that this code has solved the problem and now all the elements are displayed.

But the order has been lost and I would like all the elements to be displayed in alphabetical order.

Is this possible? What do I have to add to this code?

Thank you very much in advance!

Best regards,

#2778529

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

As you can see with our Doc:
- https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_field

use_select2 Optional. Used in parent select fields. Options are always and never. It will render the parent select field as a Select2 field or not, depending on the value set.

Works only on sites not using the new post relationships (legacy code). If used with new post relationships (Types 3,0+), it breaks the "order", "ordering" and "author" attributes. It can also break background checks like what post type to display in the select field for relationships. Warning: Do not use this attribute if not explicitly required.

So, as per the Doc when you use this attribute use_select2="never" it will affect the ordering:

#2778682

I will think about which option is best for this.

Thank you very much again!