I am working on a WordPress site that users can login to and make posts. I want to add some functionality to their posts. Basically, I want to provide the ability for the user to use reserved characters to assign a category to the post.
So, if a user posts “I am learning about #programming”, that post would be assigned to the programming category.
What is the best way to do this in the WordPress universe?
Currently I am envisioning a plugin that runs at the time the post is made to parse the user’s input and then assign the category. If so, how do I get my plugin to run at the time the post is made? Is there an API to assign categories to a post, or should I do that through manual database insertions?
You’re on the right track.
Take a look at WordPress Hooks. You’re interested in the edit_post hook.
Within a custom callback you can parse the content and look for your category hashes. Then use native WordPress functions to query an existing category or create a new one. Most of the complex logic will be in the latter part. The rest should be string manipulation.
This doesn’t necessarily have to be a plugin. This could live in your functions.php file of your theme.
Remember, the codex is your friend.