Skip Navigation

[Resuelto] toolset_get_related_posts 'orderby' does not seem to work

This support ticket is created hace 5 años, 2 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
- 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)

Etiquetado: 

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por Valeriia hace 5 años, 2 meses.

Asistido por: Nigel.

Autor
Mensajes
#1336643

Hi,

I'm trying to retrieve the children posts (clog) by date in the descending order (from new to old), but all I get is ascending (from old to new) regardless of what I try.

Before I used to run a rsort() on the resulting array to get the order I need, but now I'm trying to implement the pagination and becomes a problem.

Here is my code:

$posts_per_page = 10;
$current_page = (isset($_GET['clpage'])) ? $_GET['clpage'] : 1;

$clogs = toolset_get_related_posts($profile_id, 'profile-clog', [
        'query_by_role' => 'parent',
        'role_to_return' => 'child',
        'limit' => $posts_per_page,
        'orderby' => 'date',
        'order' => 'DESC',
        'offset' => ($current_page - 1) * $posts_per_page,
        'need_found_rows' => true,
        'args' => [
            'post_status' => 'publish'   
        ],
    ]);

I tried to change 'order' to 'ASC', to order them by ID, but it all gives the same wrong result.

Am I doing something wrong?

Thank you.

#1336665

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi Valeria

If you check the documentation ordering by date is not supported (https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts : argument number 7 ).

I'm not sure what would happen if you chose null for orderby, it *could* return the posts in the desired order, but that would be a happy accident if so, and you'd need to test. It seems to be returning the posts ordered by date under the hood, but the order argument may be ignored if orderby is null.

If 'null' doesn't help then there is no solution, I'm afraid.

I know the Types developer is resuming work on improving relationships, and so it would be worth creating a request for such an option: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1336707

Oh, so dissapointing... Your developers spend so much time on developping drug-and-drop interfaces and the basics are still not sorted...

I guess I have to redo the architecture without the relationships to sort that out.

All well. You plugins still save me tons of time. I hope to see that working in some future though )

Btw, there is a link "Edit This" under each function example in API (https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/) that everybody sees. It goes nowhere but should not be there in the first place, as I understand. Maybe you want to check it out.

Thank you and have a nice day