Problem: I would like to get the parent post Course of the current post Product using the new Post Relationships API, but it doesn't seem to be working. I have tried both of these syntaxes:
$course = toolset_get_parent_post_by_type( $product, 'course' );
$courses = get_posts( array( 'post_type' => 'course', 'numberposts' => -1, 'toolset_relationships' => array( 'role' => 'parent', 'related_to' => $product_id, 'relationship' => array( 'course', 'product' ) ), ) );
Solution: In this case, the relationships were created in the new system, so toolset_get_parent_post_by_type is not appropriate. The toolset_get_parent_post_by_type API is intended for use with legacy relationships, or relationships that were migrated from the legacy system. When specifying the relationship to query, the array syntax is intended for legacy relationships as well. The best approach in this case is to use the toolset_get_related_posts API, and the relationship slug instead of the post type slug array:
$product = get_post(69); $course = toolset_get_related_post( $product, 'your-relationship-slug', 'parent');
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Este tema contiene 6 respuestas, tiene 2 mensajes.
Última actualización por hace 6 años, 5 meses.
Asistido por: Christian Cox.