Skip Navigation

[Resolved] toolset_build_intermediary_post_title – possible to use filter retroactively?

This thread is resolved. Here is a description of the problem and solution.

Problem:

In the beta version of Types plugin, new API filter "toolset_build_intermediary_post_title", it only works with newly created intermediaries. Any previously created intermediary's title remains unchanged.

Do you have any advice on how to make this change retroactively, incase the need arises?

Solution:

You are right, the filter hook "toolset_build_intermediary_post_title" only works when you create new intermediaries, it won't work when you edit an existed intermediary, you will need to edit them one by one manually, see the workaround I mentioned in your previous thicket:

https://toolset.com/forums/topic/beta-types-relationships-api-intermediate-post-types-2nd-class-citizens/#post-624138

Q2) When you create the "Relationship", in the final step "Names", enable the options

Relevant Documentation:

This support ticket is created 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Geoffrey Cleverley 6 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#625812
Screen Shot 2018-03-17 at 3.54.40 PM.png

Hi

In a different support thread I was provided a solution to filter the new many2many relationship intermediary post titles.

https://toolset.com/forums/topic/beta-types-relationships-api-intermediate-post-types-2nd-class-citizens/#post-625485

In:

types>vendor>toolset>toolset-common>inc>m2m>association>intermediary_post_persistence.php

There is the following filter:

		 * toolset_build_intermediary_post_title
		 *
		 * Allow for overriding the post title of an intermediary post.
		 *
		 * @param string $post_title Post title default value.
		 * @param string $relationship_slug
		 * @param int $parent_id
		 * @param int $child_id
		 *
		 * @since m2m
		 */
		$post_title = wp_strip_all_tags(
			apply_filters(
				'toolset_build_intermediary_post_title',
				$this->get_default_intermediary_post_title( $parent_id, $child_id ),
				$this->relationship->get_slug(),
				$parent_id,
				$child_id
			)
		);

It works great. I have my intermediary post titles outputting a title created using the parent and child post titles, using the following code:

add_filter( 'toolset_build_intermediary_post_title', 'make_casting_intermediary_post_titles_useful', 11, 4 );
function make_casting_intermediary_post_titles_useful( $post_title, $relationship_slug, $parent_id, $child_id ){

	$parent_title = get_the_title( $parent_id );
	$child_title = get_the_title( $child_id );

	return $relationship_slug . ': ' . $child_title . ' in ' . $parent_title;
}

As you can see from the screenshot, this is working well.

However, it only works with newly created intermediaries. Any previously created intermediary's title remains unchanged.

Do you have any advice on how to make this change retroactively, incase the need arises?

Thanks again

Jeff

#626049

Dear Jeff,

You are right, the filter hook "toolset_build_intermediary_post_title" only works when you create new intermediaries, it won't work when you edit an existed intermediary, you will need to edit them one by one manually, see the workaround I mentioned in your previous thicket:

https://toolset.com/forums/topic/beta-types-relationships-api-intermediate-post-types-2nd-class-citizens/#post-624138

Q2) When you create the "Relationship", in the final step "Names", enable the options

#626055

Hi Luo,

Yeah, I figured manually may be the only way with Types.

I'm going to look into seeing if there's a way to automate it with bash and wp-cli, since the autogenerated name contains the parent and child ID.

I've closed this ticket for now, but I'll update it with a solution when I work it out.

Thanks

Jeff