creative-andrew / single-post-query-loop-selector

A Query Loop block variation that allow to search and select a single post to be displayed.
7 stars 3 forks source link

Add ability to select multiple posts #3

Open coreyworrell opened 9 months ago

coreyworrell commented 9 months ago

I realize this goes against the plugin/repo name, but the WordPress plugin slug query-loop-block-extensions still fully encapsulates it. Anyways, it would be very cool to be able to select multiple posts and order them. The PHP side of things is basically already there, would just need to adjust posts_per_page to match number of posts selected, and 'orderby' => 'post__in'.

creative-andrew commented 8 months ago

@coreyworrell

I will be adding support for this next :)

coreyworrell commented 8 months ago

I created my own based on your plugin. Perhaps it could be of help when implementing. Drag/drop sorting would be my next optimization but it's quite a bit more involved I think.

https://gist.github.com/coreyworrell/b653a82c3d92bd4461aa01646a606792

query-posts

creative-andrew commented 8 months ago

It looks really cool. I was thinking about using this: https://wordpress.github.io/gutenberg/?path=/story/components-formtokenfield--dropdown-selector

coreyworrell commented 8 months ago

@creative-andrew I thought about that too, but I didn't see any way to sort the selections when using the FormTokenField component.

Edit: and I thought it would be too easy to accidentally remove a selected post with that.

creative-andrew commented 8 months ago

Based on this: https://react-select.com/advanced#sortable-multiselect, we can expand the FormTokenField using https://www.npmjs.com/package/react-sortable-hoc

coreyworrell commented 8 months ago

I saw that as well, and it could possibly work, but that library is no longer actively maintained (see note https://github.com/clauderic/react-sortable-hoc) and they recommended using @dnd-kit instead, which looks a bit more involved.

Either way though I felt that the multi-select token style was not as user friendly for managing the selected posts. Just my opinion of course.