Skip Navigation

[Resolved] How to create a unique reference number and use it as CPT post title

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.

Our next available supporter will start replying to tickets in about 0.27 hours from now. Thank you for your understanding.

This topic contains 3 replies, has 2 voices.

Last updated by KeithM7209 1 month, 1 week ago.

Assigned support staff: Waqar.

Author
Posts
#2091585

Tell us what you are trying to do?

- I have a custom post type called 'Reference'
- The user is able to input a 'Reference' in the front end via a Post Form
- Each 'Reference' title is currently set by the user inputting into a text field (which is actually the 'post_title' field). On my form itself, I just label this field the 'Project ORC Ref'.
- It is required that ALL "Project ORC Ref's" are to be UNIQUE (therefore the post_title of each Reference post also needs to be unique)
- Currently, when a user inputs a Reference into the post form, I have some code (shown below, which is in my functions.php file) which checks if the post_title is unique, and if it's not it throws an error message, it stops the post from saving, and will therefore require the user to change the 'Project ORC Ref' field to something else, and it will only save it this is unique.

** That methodology worked fine when I was only required to get website admin Users to input References (as they could keep a separate list of ORC Ref's and just manually input a unique one each time). However the requirements for this have now changed, as non-company staff users (ie clients of the company itself) are now able to input their own References into their account.

So, what I really need now, is for when this post form loads, is for toolset to be able to generate a unique post title and to put this in as the value into the post_title field (also to make it so that the user is unable to change this field).

So please can you tell me how I could achieve this? I know that of course the actual post_id number will always be unique, so I would have no problem in using this (I would just like possibly to be able to prefix this with 'ORC-' as well).

Thanks so much in advance for your help 🙂

Keith

Is there any documentation that you are following?

I have tried searching the forum but I could not find anything similar to this issue

Is there a similar example that we can see?

No

What is the link to your site?

I can provide links / logins etc if you provide me with a private box to put them in

#2092363

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Keith,

Thank you for contacting us and I'd be happy to assist.

To programmatically generate a unique post title, you can use the "cred_save_data" hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

You'll find an example snippet for a similar request in another thread:
https://toolset.com/forums/topic/what-is-the-url-naming-convention-for-posts-created-with-cred-forms/#post-2089301

Feel free to adjust it as needed 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

#2092623

Hi Waqar,

After some more thought, I've actually been able to achieve what I needed with some custom javascript. So I will now close this ticket.

Many thanks for your help though it is greaty appreciated 🙂

Keith

#2092625

My issue is resolved now. Thank you!