I would like to auto-increment the standard WordPress title starting from a certain number (i.e. 10000) and each time admin submits a new post, it goes up by 1. I want to know if this would work hand in hand with the built in Toolset option of hiding the Title of a CPT. So I will hide it and have it auto-incremented so that the admin will never need to deal with it, yet there will be ID's to search from in case necessary.
Essentially you will want to start your post titles at 0 correct? Then whenever a new post is created that post will then be an increment of the first post's title ?
So I would like to start off at the number 10,000 because I am already importing 9000 posts to the CPT, and am going to import them directly to the WP Title field, so I would like to start from a unique non-duplicate number. From there I would like it to go up by 1 for each new post created.
Whether or not they would be completely numeric is a good question. I would primarily like to be able to append a two letter prefix dependent on the specific custom categories created (i.e. if admin selects the category "shoes", the auto-increment will be SH10001. If admin selects the category "heels" then it'll be HE10001). However, if that is not possible then I would keep it to just numbers, and have each new post go up incrementally numerically each time. (i.e. 10001, 10002, 10003).
I understand now what you want to achieve, however this will be a highly customized solution which would fall outside of our support scope as the solution would be specific to your site.
There are 2 ways that we can proceed here. If you're familiar with PHP and coding then I can provide recommendations and resource materials and guide you through crafting the solution.
If you're not familiar with php and coding then it would be best to have a contractor craft up this custom solution for you.
Should this be the case you can seek assistance by going to the link below. https://toolset.com/contractors/
I would love to first give it a shot by myself, would you be able to start me off with some generic code or documentation to where I can find it? Does the above thread that I mentioned help me at all?
I would look into both solutions, either just adding incrementally without the letters in the beginning (which I'm assuming is more simple), and also the option for adding letters. But what I definitely need, is the ability to start from number 10,000.
Sure first you will perhaps need a custom field to store the current number of your post. This means that you'll have a number field to hold the record so it can be used to check against for the new post.
You will need to identify whether you're creating the post on the frontend or backend as the hooks will vary but the concept will remain the same. If you're using the backend then the hook you should be looking at is this one below. https://developer.wordpress.org/reference/hooks/save_post/
Here is an example code of how you will set the post title. hidden link
This should provide a suitable example on how to get a post meta value and append it to the post title.
Thanks for the info Shane, I'm going to take a look at the docs you sent me. Just to clarify, you mean I will have to first create a custom field, let's say call it "Title ID" and then from that custom field I will be sending the data over to the title?
I am potentially going to need this for the frontend form as well, is there a link to that too?
let's say call it "Title ID" and then from that custom field I will be sending the data over to the title?
That's correct, so this field will be used to check against to auto increment the title for the new post. Essentially the process is going to be like this.
Submits new post -> Check previous post Title ID field to get the last reference number -> Auto increment the Title ID of the previous field by 1 -> Store this into the Title ID field for the new post as well as the Title of the post.
Got it, okay thanks for explaining so clearly. I just had one or two more questions:
The Title ID that we'll need in order to accomplish this, is there a way to hide it from the admin so that they don't get confused about what is supposed to get entered there? It really is only necessary for this piece of code, but otherwise it should be hidden correct?
In order to disable the title field you will need to do it through the post type settings. This can be done by going go to Toolset -> Post Types and edit the custom post type.
From there go to "Sections to display when editing" and disable Title.
This should remove the post title field from your CPT so that admin cannot edit it.