Saltar navegación

[Resuelto] Create a family relationship between contacts

This support ticket is created hace 4 años, 10 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.

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/Karachi (GMT+05:00)

Autor
Mensajes
#1513717

I have a casting database with a custom post type ‘actor profiles’

Sometimes we cast families too, so for each member of the family we Create a separate actor profile, so we can search for the actor independently.

But we would also like to see in the profile, if an actor is related to another actor and if yes in what relationship (father/child, siblings, grandmother/grandchild, etc) and to what families they belong.

This should allow us to search for all members of a particular family and see how the various actors are related to each other.

I have thought about the following approaches, but I am struggling with setting this up, because:

a) toolset does not allow me to build a relationship between the same custom post type

b) when using a taxonomy I could only specify the same family, but not the relationship between the single family members

c) when setting up a new custom post type ‘family’ and creating a many to many relationship with the actor profiles I can connect the actor to a family and with an intermediary post type even define the role of this actor in the family, but how can I define the relation between two actors in the same family?

I am looking forward to any suggestion or new approach on how to solve this.

Here Is the link to the page in question;
enlace oculto

Thanks a lot.
Tobias

#1515825
relationship-fields-example.png

Hi Tobias,

First sorry about the delay in reply, as we had an unusually high number of tickets in the queue.

Your observation is correct and currently, Toolset doesn't support relationships between the same post types. You're welcome to submit this as a feature request at:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

For now, you can use the following approach as a workaround:

1. The steps that you mention in point "c" should work just fine for storing information about an actor profile with respect to a single-family and this will also let you perform a front-end search to show all actors belonging to a particular family.

2. To establish relationships between two actors, you can dynamically populate options of a "select" type custom field, from the available actor profile posts, using the "wpt_field_options" filter:
https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options

Note: This approach won't be useful for performing front-end searches, but would still allow you to display relationships at an individual actor profile's level.

For example, you can add a new repeating field group "Actor Relationships" for your "Actor Profiles" post type and include two "select" type custom fields, as shown in the attached screenshot:

- Relationship: will hold information about what is the relationship that we're establishing
- Relationship To: will hold information about which actor profile we're establishing this relationship with

Note that in the screenshot, "Relationship To" field doesn't have any options defined, because we need to populate them dynamically using the "wpt_field_options" filter.

Assuming your post type slug is "actor-profile" and target field's title is "Relationship To", the code will look like this:


add_filter( 'wpt_field_options', function ( $current_options, $title_of_field ) {
	if ( $title_of_field != 'Relationship To' ) {
		// not our "Relationship To" field
		return $current_options;
	}

	$options = array();

	// add first empty value
	$options[] = array('#value' => '', '#title' => '--- not set ---');

	// get all items from actor-profile posts
	$args = array( 'post_type' => 'actor-profile', 'posts_per_page' => -1, 'post_status' => 'publish', 'orderby' => 'title', 'order' => 'ASC' );

	$results = get_posts( $args );
	if ( $results ) {
		foreach ( $results as $post ) {
			$options[] = array('#value' => $post->ID, '#title' => $post->post_title);
		}
	}

	return $options;
}, 10, 2 );

This will populate all actor profiles posts as options for this field, using the post titles as the option lable and post ID as the value.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1518459

Thx Waqar, this sounds great, I will try it out, asap and will get back to you. Thx! T

#1520465

You're very welcome Tobias and please let me know how it goes.