Skip Navigation

[Resolved] Generate a post slug with front-end form using values from three custom fields

This support ticket is created 5 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 5 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1291205

I have created a front-end form to allow users to create 'teacher profiles' to be displayed as single posts and an archive.

I want to auto-create the post title by concatenating values from three custom fields on the form and having them auto-populate the title field, which will then create the custom slug I need - it might for example be teacher/02/michael/london with teacher being the post type.

1) I need one field to be an auto-number field increasing by one for each post created - I can't see how to do this so haven't added it yet.
The second field is the teacher name, the third is their location, both of which the user will complete.

2) How can I combine these three values (assuming the auto-number field is possible) to create the post title during the posting process and thus create the matching slug?

At the moment, while I have a php snippet in functions to set the post title once the post has been submitted, the posts all have slugs like /cred-auto-draft-48f057167b095ecf5d004cbc79629a96 as I assume the title is set after posting and thus after the slug is set. These are user-created posts so being able to manually change slugs in admin is of no help here.

In the past I have used Formidable forms and ACF together to do the same thing and it's easy - you just cut and paste a little snippet of js FF provide into a field on their post form. However, while I'm sure it's equally simple with tools, I can't see how to do the above.

I tried looking at various shortcodes and other documentation but while some may be useful (I can't tell) there aren't any copyable examples to adapt and use, meaning they're wasted on a non-coder.

Sorry, the site isn't live so no links, as I'm still trying to decide whether to use tools or go back to what I know.

Thanks for whatever help you can give.

#1291395

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You auto-generate the post title you can use the Toolset Form's hook cred_save_data . You can add this hook to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

Please check the following related ticket that may help yo:
=> https://toolset.com/forums/topic/auto-generate-post-title-and-nameslug-by-combining-other-fields/#post-498090

More info:
=-> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data