Skip Navigation

[Resolved] Create a post-selector dropdown like toolset's with select2?

This support ticket is created 5 years, 10 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
- 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)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 5 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1206757
select2.png

Hi

before i invent the wheel again... i need a select box in the frontend where the user can search and select an extensive post-collection. i was looking at select2, and noticed, that you guys use also select2 for post-select (see image, i need exactly this functionality).

is there any way toolset can support me in showing a select-box like this in the front-end? or do i just have to include select2 myself and build it myself?

thanks!

#1207091

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

If it is not in a context where select2 is already included on the page (e.g. a form with a parent post selector) then you will need to manually enqueue the select2 assets.

You could create a View which a list of posts as a select dropdown and then instantiate select2 to convert it, but what are you going to be using this dropdown for?

You can't, for example, filter Views by standard posts like the post title.

I'm not sure of the context here.

#1207205

It's an administrative extension on a website where data is entered / collected in the frontend of wordpress. (a newsletter template).
There are input-boxes where the editor can select a post. currently the user enters the post-id and the system gets the post via ajax.

i would like to replace this lookup with a more comfortable aproach where the user enters searchstring and has a dynamic dropdown-list. i need EXACTLY what you got you in the posts-dropdown of the screenshot - a dropdown in a modal. so i was wondering, if there is a way to "invoke" this myself in the frontend.

or as you say: simply enqueue the assets myself and implement select2 and the functionality i need from scratch.

but since you got already exactly what i need as a standard-dialog in the backend, i was hoping there's a way to hook into that functionality in the frontend and in my own code.

#1207438

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

A front-end form to publish a child post would have a parent post selector that works in the same way as your screenshot from a backend parent post edit screen, but it is not possible to extract that to be used elsewhere, you will have to set it up yourself.

But as I mentioned before you should be able to make a View that lists the posts and which outputs them as a select input (unusual, but I expect it would work) where the options are generated by the loop, insert the View where needed on a front-end page, and trigger select2 to convert the input from a standard dropdown.