Skip Navigation

[Resolved] role_name_to_return for 1 to 1 relationship

This support ticket is created 3 years, 10 months ago. 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)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 3 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1938641
Edit-Specials-Angebote-Relationships-‹-hunde-urlaub-net-—-WordPress.png

Hi,
I have a one to one relationship between post a and post b. I have an id for post a and I want to retrieve the related post. Looking at the api docs, for toolset_get_related_post my api call should look like

toolset_get_related_posts(post_id_a,relationship_slug, {parent || child})

I'm at loss to choose between parent and child! Shouldn't it be optional anyway (documentation says no)?

In the example for the docs it suggests

toolset_get_related_post( $book_id, array( 'writer', 'book' ) );

This example doesn't match the the arguments offered for the function.

There should be a parent, but I how do I determine which it is?

I attach a useful image of the relationship.

#1939209

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You wrote:
I have a one to one relationship between post a and post b. I have an id for post a and I want to retrieve the related post. Looking at the api docs, for toolset_get_related_post my api call should look like

toolset_get_related_posts(post_id_a,relationship_slug, {parent || child})
==>
But the function should be used is: toolset_get_related_post()

Now, later you said, that you are using the function: toolset_get_related_post():

toolset_get_related_post( $book_id, array( 'writer', 'book' ) );

but you should adjust the relationship array array( 'writer', 'book' ) to your post-relationship slug.

So, if you pass the child ID and without specifying the third argument parent/child, the default is parent, for example:

$child_id = 999;
$parent_id = toolset_get_related_post($child_id,'cpt-promoter-artist');

The above function will return the parent ID.

To get the child ID, you will require to pass the parent ID.

$parent_id = 222;
$child_id = toolset_get_related_post($parent_id,'cpt-promoter-artist','child');

The above example will return the child ID.

In your case, as per the screenshot you shared:
- https://toolset.com/wp-content/uploads/2021/02/1938641-Edit_Specials_Angebote_Relationships_hunde_urlaub_net_WordPress.png

You should consider the Specials post type as parent and Special Angebote will be the child post type.