Hello,
I'm trying to get a website like this hidden link
I find this way by the moment:
I created two CPT's:
- Servicios (Services) hidden link
- Locaciones (Locations) hidden link
And a many to many relationship: Servicios-Locaciones (Services-Locations) with ¨Intermediary Post Type visible in WordPress admin menu¨ option active. Because this is the most important content I will want to posisionate.
The problem is that the title and the slug for this intermediary post is not friendly. I get a post with the relationship name and the ID's of parents posts:
Title: "Servicios Locaciones: 10 – 11" -
URL: hidden link
But I'm specting something like:
Title: "Albañiles en Barcelona"
URL: hidden link
But created by default and not having to do it manually as the content will be massive.
1) Is it a way of setting this somewhere?
2) Is there another way of getting a URL structure like the example website with Toolset?
Note: The listing items at ¨Servicios¨, that would be the "Services providers", is a content that comes from an external DB. So that's why I didn't not create a CPT for that. (Just to clarify my whole idea.)
Hi,
Thank you for contacting us and I'd be happy to assist.
To set a custom title and the post slug for the intermediary post, you can use the 'toolset_association_created' hook:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created
For example, suppose the relationship slug is 'book-post'. The code to update the post title and slug would for this relationship's intermediary post would look like this:
add_action( 'toolset_association_created', 'custom_intermediary_post_title', 10, 5 );
function custom_intermediary_post_title( $association_slug, $parent_id, $child_id, $intermediary_id, $association_id ) {
if ($association_slug == 'book-post') {
$parent_title = get_the_title($parent_id);
$child_title = get_the_title($child_id);
$new_title = $parent_title.' en '.$child_title;
$updated_data = array(
'ID' => $intermediary_id,
'post_title' => $new_title,
'post_name' => sanitize_title($new_title),
);
wp_update_post( $updated_data );
}
}
You can replace 'book-post', with your target relationship slug and the above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar
It worked perfectly.
Thank you!