Support » Plugins » Hacks » Need help adding terms programatically

  • Resolved crsneilhedley


    What I have: A custom post type, “baseball_team”, with a taxonomy called “active-roster”.

    What I want: To run a function in cron once a week that scans the rosters and injury lists of the teams and adds any new players.

    My question: I have all the data, I just need to find a way to automate the process of getting the terms in. For example, if the roster for the Yankees, it won’t add “Derek Jeter” if Jeter’s already in there, but it WILL add “Sheldon Lefkowitz” if the Yankees pick him up in a trade.

    Reading what the various taxonomy functions do has made my head hurt. Can someone help me make sense of it? (And for what it’s worth, everything above before the words “I just need to find a way” is non-negotiable. I’ve decided what I want, and just need a hand from someone smarter than me to make it happen.)

Viewing 1 replies (of 1 total)
  • crsneilhedley


    Never mind, found the answer in a combination of places. (Don’t want to disturb anyone’s nap, just wanted to post a solution in case someone Googles this term someday.)

    The info on this page says that to add the name “Bob” to the taxonomy “person” in post 123, I’d do this:

    wp_set_object_terms( 123, 'Bob', 'person' );

    My concern was what would happen if “Bob” already exists in the “people” list. But on this page it says…

    Creates the term and taxonomy relationship if it doesn’t already exist.

Viewing 1 replies (of 1 total)
  • The topic ‘Need help adding terms programatically’ is closed to new replies.