Skip Navigation

[Resuelto] Order by post__in

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
Add post__in to Query / order

Solution:
It is not simple to add a sorting option for `post__id` since we use that `post__in` query argument in several places, not just the filter by post IDs, so there is no actual way of setting the posts that this sorting option would apply as order list.
The same for `post_name__in` and `post_parent__in`, we cannot offer the posts to include in that sorting option.

This support ticket is created hace 6 años, 7 meses. 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Etiquetado: 

Este tema contiene 6 respuestas, tiene 2 mensajes.

Última actualización por Twig hace 6 años, 7 meses.

Asistido por: Beda.

Autor
Mensajes
#668923

Hi -

I'm looking to pass Post IDs into a View (using the shortcode parameter, as it will vary from page to page) and I want to maintain the order of the posts as passed. I.e. [wpv-name posts="10,5,200"]... should display posts in the order 10, 5, 200 - not in the SQL-native order of 5, 10, 200.

Here is a thread from a few years ago:
https://toolset.com/forums/topic/order-the-items-in-a-view-by-ids-order-not-ascending-or-descending/

I can see & use the fix - but I was wondering why you guys can't just add an "Order by Post__In" option to the UI for the Views page? This has been supported in WP core since (I think) v3.5.

Thanks

#674434

I think perhaps the filter priority needs to be > 99. It doesn't work for me when priority is 99, but does work when set to 999.

#678309

As our document outlines, every filter must be above 100.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#679036

Ok thanks @Beda - I guess the ticket from 3 years back just used the wrong priority.

Any ETA on when you guys might add "Order by post__in" to the native View options? Seems like it would be an easy addition to the dropdown & $query_args logic, no? In fact, it actually seems to already work when you set it in the Views shortcode manually like:

`{!{wpv-view name='...' postids='355,370,372...' orderby='post__in'}!}`

Thanks!

#683814

Well, we use that in several places yes.
https://toolset.com/forums/topic/add-post__in-as-order-by-option/#post-515214

But ordering by it won't be implemented.

#684430

Thanks Beda. That's funny that you referenced my request from a year ago 🙂

I still don't quite understand the limitation you mention, but since that filter is easy enough to add, it's not a big deal.

#717417

In case this helps anyone else looking for a programmatic way to order by post__in, I've found that you can't pass 'post__in' directly into the shortcode because Views strips the string "post" out of any value.

However you can pass a custom value (like orderby='ids') then have the filter function catch any shortcode with that param value, and update it to be 'post__in'. That way, you don't need to hard-code View IDs into your filter.