Skip Navigation

[Resolved] Automatically populate CPT-title by titles of related CPTs

This support ticket is created 2 years, 4 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Shane 2 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#2462999

Hi there,

I'm looking for a solution to automatically create titles if a CPT 1 is getting related with CPT 2 and cpt 3.
Something like this: https://toolset.com/forums/topic/add-auto-generate-post-title-from-fields/#post-1213248 but not with custom fields.

The idea is to create an Event (CPT 1) that is getting a name from an Artist (CPT 2 - First Relationship) and a Location (CPT3 - Second Relationship) so that it looks like Artist @ Location when we save it.

Thanks for an idea or a hint and kind regards, Alex

#2463069

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alexander,

Thank you for getting in touch.

The concept here is essentially the same however i'm not able to write this custom code for you.

Are you relating CPT1, CPT2 and CPT3 all on the same form ?

Meaning is there are relationship field on the form for CPT1 that allows you to link it with CPT2 and CPT3 ?

Please let me know.
Thanks,
Shane

#2463073

Hi Shane,

yes. Ideally we want to create a post event fill the needed data and then connect with CPT 2 (Artist) and CPT 3 (Location).
After saving the Title of the Event should be CPT-2-Title @ CPT-3-Title...

Kind Regards, Alex

#2463209

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alex,

In such a case then we might be able to get the ID's from the frontend form for each post in the relationship and get the post titles for each post.

Do you know how to check the post request payload in your browser?

If not you can let me know and I can provide you with the correct $_POST request variable to use when you're retrieving the value from the $_POST request.

I will need access to the form to be able to do this.

Thanks,
Shane

#2463211

Ok, not really, i'm not a programmer... but we didn't plan a frontend-post-submission, the post are created in the backend by the user. We have to prepare everything in the beginning of next week, we just found out, that it not possible without custom code.

thanks

#2463217

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Alexander,

In this case then you will need to make use of the relationship functions to get the posts in the relationship

Something like this is definitely in the realm of custom coding as wordpress core itself doesn't support the use of custom fields for post titles.

With this function here you're able to get the related post information.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

This will allow you to get the ID of the related post. From there you can use this to get the title of the posts.
https://developer.wordpress.org/reference/functions/get_the_title/

Once you've got both titles then you should be able to combine them to form your final post title.

Please let me know if this helps.
Thanks,
Shane