Saltar navegación

[Resuelto] How to retrieve a list of all relationships a certain post type is used with

This support ticket is created hace 1 mes, 2 semanas. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Este tema contiene 4 respuestas, tiene 1 mensaje.

Última actualización por Minesh hace 1 mes, 2 semanas.

Asistido por: Minesh.

Autor
Mensajes
#2783065

Tell us what you are trying to do?
I am trying to get a list of all Relationships in which a certain post type is in.

Is there any documentation that you are following?
I was hoping the Toolset Relationship API had a method for this, but apparently not.

---

1. Post Types (unfortunately?) are managed with ACF
2. Relationships are managed with Toolset (all M2Ms)
3. I need to retrieve ideally the slug of all relationships in which each post type is used in. See example below of a ideal dummy function:

error_log( print_r( toolset_get_relationships( 'post-type-slug'), true) );

The above, ideally would give me something like:

array(
    'relationship-one',
    'relationship-two',
    'relationship-three',
)

Is there any inbuilt method I can use? The https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/ doc has nothing, only data about ONE relationship or data about ONE post type.

I am pretty sure I miss something since such an operation I imagine is used often - for example, in Toolsets backend (but only if the post types are managed with Toolset) one can see a list of relationships in which this specific post type is...)

Thanks for any insight.

#2783073

So it seems I can use something like below:

toolset_get_relationships( 
		array( 
			'type_constraints' => array( 
				'child' => array( 
					'type' => 'my-post-type'
				)
			)
		)
	)

Leaving this open to hear Support's input on it since this is not a documented api function

#2783091

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There is no such function available.

As stated with the Doc, you can get information about related post type:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post_types

For example:

// If there is a relationship appointment between "Doctor" and "Patient" post types we use the following
toolset_get_related_post_types( 'parent', 'patient' );

// This will return array( 'doctor' => array( 'appointment' ) )

Using the function "toolset_get_relationship" you can get the post-relationship configuration information:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_relationship

#2783093

Right - but that does not get me all relationships in which the post type is
So I need to know ahead which relationship I query, as opposed to the toolset_get_relationships() (undocumented) function which gives them all by post type (and role of post type).

Do you think it is a high risk this function changes in future?

#2783094

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Well - I can not guarantee about the function that is not added to post-relationship API doc which is publicly available. If you see that function within Toolset plugin source and want to use it, you will have to use it at your own risk as I do not have any ETA or any commitment that it will have any change it future or not.