Add term to a taxonomy (2 posts)

  1. hugooliveira
    Posted 4 years ago #

    I'm developing a plugin. At the hook 'init' I'm creating a Custom Post Type and a Taxonomy for that CPT. I want to create some default terms to the taxonomy after activating the plugin. But if I create the terms at the hook 'init', all the time refreshing the page the terms are created even if I delete or edit the terms. If I create the terms at the hook 'activate_plugin' the terms aren't created because the hook 'init' is called after the 'activate'.

    Does somebody know how I can do this? thanks

  2. Mark Root-Wiley
    Posted 3 years ago #

    I'm on the search for the same question, but here are some thoughts. Let's figure this out together, eh?

    Check out register_activation_hook, this will cut down on the number of times your function fires.

    To finish things out, I think we'll need to check for a term's existence and only add it if it doesn't exist. For me, I want to encourage people to change the term title or slug if they desire, so I'll have to check by ID.

    I'll try to report back if I learn anything, and let me know if you ever found an answer.

Topic Closed

This topic has been closed to new replies.

About this Topic