• Resolved jhcolead

    (@jhcolead)


    Does anyone know if you can create new categories automatically when you create posts, pages or custom posts?

    I’m looking for either a plugin that could handle it or advice if any one else has tried it.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Not sure why you would do that. How would the plugin know what you wanted to call the category?

    Why not create a post and click new category. Then you can name it exactly how you want.

    Thread Starter jhcolead

    (@jhcolead)

    It’s to call the category the same name as the post. Also to avoid any issues with spelling mistakes and repetition in categories.

    I’m sure it’s do-able. Just wondered if anyone had come across it before.

    Moderator bcworkz

    (@bcworkz)

    You should recognize that your request does sound unusual. In a sense it is redundant and departs from typical uses of categories. All the same, it’s possible.

    Hook one of the actions used when posts are inserted, like ‘save_post’. I’d suggest ‘draft_to_publish’ because it is specific to new posts. But for any post type, so you should conditionally add categories based on post type if you have other post types associated with categories where this should not happen. However, it will not pick up on changes to the title. If that’s required, used ‘save_post’ and confirm if it fired for an update or not, and if so, if the title has changed.

    In the action callback call wp_insert_category().

    Thread Starter jhcolead

    (@jhcolead)

    I do realise this is an odd question. Normally we would find these solutions ourselves, but I wanted to open this up to the community to see what kind of response I would get back.

    We have a solution we are working on that already existed in another form. Just needs refinement.

    Thanks for your replies and help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Automatic Categories from Posts’ is closed to new replies.