Skip Navigation

[Resolved] Forcing a user to enter field data in slug format or converting entry to this

This support ticket is created 5 years, 7 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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by grahamG 5 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1250511

I have a plugin that creates collaborative groups (bbpress). I want to automate creation of links to these groups by my users. The plugin converts the group names to a slug format for its URL - all lowercase letters and spaces replaced by -'s. E.g. hidden link. So either I have to convert what they enter as the name to this format e.g. Chief Academic Affairs Officers to chief-academic-affairs-officers, or I have to enforce use of lowercase and no spaces. Is there a way to do either of these in custom fields in Toolset?

#1250633

Hello,

There is't such a built-in feature within Toolset plugins, you might consider custom codes, for example, setup two custom field s:
- Group name
- Group slug

After user fill the Group name, and save the post, use WordPress Action hook save_post to trigger a PHP function:
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

In this PHP function, get the "Group name" field value:
https://developer.wordpress.org/reference/functions/get_post_meta/
get the slug format value:
https://codex.wordpress.org/Function_Reference/sanitize_title
save the slug value into Group slug into field "Group slug"
https://developer.wordpress.org/reference/functions/update_post_meta/

For your reference.

#1263565

My issue is resolved now. Thank you!