Skip Navigation

[Resuelto] Sort by Fields From a Related Post

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

Problem:

Sort the view results by a custom field "Seating Capacity" of another post type.

Solution:

There isn't such a built-in feature within Views plugin, and it is a limiation of WordPress:

https://toolset.com/forums/topic/sort-by-fields-from-a-related-post/#post-1138055

Relevant Documentation:

https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

This support ticket is created hace 6 años, 1 mes. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Etiquetado: 

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por leeR-6 hace 6 años, 1 mes.

Asistido por: Luo Yang.

Autor
Mensajes
#1137754

I have a view displaying Intermediary Posts.

enlace oculto

I can display fields from a relationship parent.

[wpv-post-featured-image item="@page-page-relationship.parent"]
<h2>[wpv-post-title item="@page-page-relationship.parent"]</h2>
[wpv-post-excerpt item="@page-page-relationship.parent"]
[types field='seating-capacity' format='FIELD_NAME: FIELD_VALUE' item='@page-page-relationship.parent'][/types]<br>
[types field='sort-order' format='FIELD_NAME: FIELD_VALUE'][/types]<br>

Note that sort-order is from the current post, not the parent.

The sort feature works using the sort-order field. However, it does not work using the post-title or seating-capacity (which are from the parent).

I suspect I need to modify this code to somehow reference the parent.

[wpv-sort-orderby type="radio" options="field-wpcf-sort-order,post_title,field-wpcf-seating-capacity" label_for_field-wpcf-sort-order="Field - Sort Order" label_for_post_title="Post title" label_for_field-wpcf-seating-capacity="Field - Seating Capacity" orderby_as_numeric_for="field-wpcf-sort-order,field-wpcf-seating-capacity" orderby_ascending_for="field-wpcf-sort-order,post_title,field-wpcf-seating-capacity"]

Since I can display post-title and seating-capacity, it seems like I should be able to sort by them. How can I make the sort work on this page?

Thanks
Lee

#1138055

Dear Lee,

There isn't such a built-in feature within Views plugin, and it is a limiation of WordPress.

Views is using wordpress class WP_Query to query the posts, if you are going to sort the results by a custom field "Seating Capacity", all posts should have value in custom field "Seating Capacity", but in your case the custom field "Seating Capacity" is in another post type, so it conducts the problem:
No items found.

More help:
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
'meta_value' - Note that a 'meta_key=keyname' must also be present in the query.

In my opinion: don't use parent post field to sort the result.

#1138190

Thanks. I'll do things another way.