Sauter la navigation

[Résolu] Split: How to convert a normal dropdown to a select2 dropdown

This support ticket is created Il y a 5 années et 11 mois. 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

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

Dernière mise à jour par francescoG-3 Il y a 5 années et 10 mois.

Assisté par: Nigel.

Auteur
Publications
#1207722

Nigel, sorry, I write you here, because I need assistance in another thread, about using the relationship posts in child posts custom search and select the value with "Select2".
https://toolset.com/forums/topic/how-to-select-a-related-post-value-from-the-custom-search/#post-1207317

So, in this topic (https://toolset.com/forums/topic/drop-down-menus-for-countries-and-cities-in-dependency/), with the Christian Cox suggestion and Toolset guide, I have used the Toolset Relationship functions, to set some post dependencies. Well, I have created the Profile CPT that it is child of Città CPT, that it is child of Provincia CPT, that it is child of Regione CPT, that it is child of Stato CPT, all with parents with an address custom field.
And so, now I'm trying to create the Custom Search and I cannot add the form to search the posts about its dependencies (parent, grand parent, grand grand parent, grand grand grand parent).
So, a solution that I have thought is to create the relative Address Custom Fields into Profile CPT posts, to dynamically save the values about the Parent, Grand Parent, etc... Address Custom Fields. But I don't know what custom code I need to use...
And also, If there is a solution to do what I need, to integrate the Select2 to select the items in Custom Search, because only the Città CPT have up to 8000 items....

Can you help me on that? Because if there are no solutions to do that, all work and all the time will be lost...
Can I pay to have what I need!!!!

#1207742

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Referring specifically to the question of how you can make a select field with many options work like a select2 dropdown, you can convert the dropdown to select2 yourself.

First you will need to enqueue the select2 JS and CSS files.

See lien caché for the files you will need, and https://developer.wordpress.org/themes/basics/including-css-javascript/ for how to enqueue them so that select2 is available on your page on the front end.

Then, as per the select2 documentation (lien caché), you simply need to instantiate select2 on the select input, which would mean adding something like the following to the custom JS section of the View where you want one of the select filter inputs to work via select2:

$(document).ready(function() {
    jQuery('#wpv_control_select_wpv-relationship-filter').select2();
});

(You will want to use the browser inspector to determine the best selector to target the select input element.)

#1218480

This solution works fine and does what I need!!!
Very Thanks!!!