Skip Navigation

[Resolved] Split: How to assign a specific handler to a dog for each event

This support ticket is created 5 years, 8 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
- 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)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 5 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1227628

thnk you waqas that sorted it lovely , i have hot a bit of a road block here upon entering data , when i add a dog to the event results , i also have a handler for the dog , i can enter multiple handlers for each dog but cant seem to assign a specific handler to a dog for each event , it shows all handlers for the dog on each event , rather than just the handler for the dog at that one event. any thoughts?

#1227645

Hi Martin,

If your goal is to save a "Handler" info with an individual dog, with respect to an individual event, you can add a new select type field to your "Events Dogs" relationship.

Step 1 screenshot: hidden link
hidden link

Step 2 screenshot: hidden link
hidden link

You can name this new "Select" field as "Dog Handler for the Event" and you don't need to add any options, as they'll be included programmatically.
Step 3 screenshot: hidden link

Next, to generate a list of all handlers for this new field, you can add the following code, at the bottom of your active theme's "functions.php" file:


add_filter( 'wpt_field_options', 'populate_dog_handler_select', 10, 3);
function populate_dog_handler_select( $options, $title, $type ){
	switch( $title ){
		case 'Dog Handler for the Event':

			$options[] = array(
					'#value' => '',
					'#title' => '- Select -',
			);

			$args = array(
				'post_type'        => 'handler',
				'posts_per_page'   => -1,
				'post_status'      => 'publish'
			);

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

		break;
	}

	return $options;
}

Important note: Please make sure that the "Dog Handler for the Event" matches the title of this new field and the "handler" matches the slug of the "Handlers" post type.

As a result, when you'll be adding/connecting a dog with an event on the event's edit screen, you'll see this new field with a list of all available handlers to add to this entry.
Screenshot: hidden link

Note: this list will show all handlers and not the just the ones connected to the selected dog. To show only those handlers, which are connected to the selected dog, complex custom programming will be needed, which is beyond the scope of support that we can provide.

For more personalized assistance around custom code, you can always consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar