Automatic short code generation is a technique that I see many plugin authors use but unfortunately, I have yet to come across a tutorial that details this subject so I am hoping that someone in this community will help me understand it clearly as I am struggling to implement it in my own plugin.
The automation process that I am talking about is this: After a user selects/inputs parameters in a plugin's custom post type metabox(es), he or she saves the information and immediately a shortcode is generated and outputted within a custom post column (others also display a message containing the shortocde whereby the user simply copies it and pastes it wherever he or she intended to use it).
For example, in a plugin that displays book information, a user inputs the book name, ISBN number, category under which it falls under etc. After keying in all those details, a shortcode '[book id="1"]' is automatically generated after performing a save/publish action. Keying in details of another book also results in the same action with only the ID changing i.e. it generates '[book id="2"]'
My problem is how this is done. More specifically:
- How do authors fuse the functionality of saving metabox values with the functionalities of generating a shortcode?
- Within the above process, how are IDs auto generated?
Use the book example above,I am hoping someone can explain to me clearly how the 'automation process is done'. Even though I haven't given a code sample, I feel the above is enough to get an answer(plus it helps focus on the actual problem). However, if you do really need something then I will code up a sample :-)
As a bit of a background:
- I know how to create custom post types
- I know how to create custom columns for custom post types
- I know how to output values into those custom columns
- I have an understanding of saving custom values from metaboxes
- I know how to create shortcodes(including ones with parameters). The thing now is that I have to type the shortcode (including parameters) manually in the front-end and this is the process I want to automate (i.e. autogenerate shortcode and place it somewhere like custom columns, user simply copy pastes to wherever he/she wants the output to appear)