Dynamically Generating Category based on Title
-
Hi,
I’m trying to dynamically generate a category which would have the same name as the custom post title.
This category would be generated as soon as the user presses the publish button. It works with hard coded value, i’m having trouble setting the title to a variable and using that variable in the code below.
essentially dog would be replaced by $category_variable, but I can seem to figure out how to set the title to the variable.
This code is found in a custom post type which resides in a plugin.
Thanks
function generate_category() { wp_insert_term( 'dog', 'category', array( 'description' => 'Dynamically Generated Category', 'slug' => 'dog' ) ); } add_action('publish_post', 'generate_category');
The topic ‘Dynamically Generating Category based on Title’ is closed to new replies.