WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to programmatically add NEW categories? (4 posts)

  1. Probocop
    Member
    Posted 3 years ago #

    Hi, I have written a script that takes an XML feed of some news, and inserts each news story as a post into WordPress using wp_insert_post().

    Each of these news stories has a category that I would like to add to WordPress also.

    My question is, how can I create a NEW category and assign the post to that category using wp_insert_post() (or any other function)?

    Thanks!

  2. Joseph
    Member
    Posted 3 years ago #

    Create the categoory with http://codex.wordpress.org/Function_Reference/wp_insert_category

    Get the category ID with http://codex.wordpress.org/Function_Reference/get_cat_ID

    And assigned category to post in wp_insert_post().

  3. Probocop
    Member
    Posted 3 years ago #

    Perfect, thank you very much.

  4. chizet
    Member
    Posted 3 years ago #

    Would this all be written in functions.php or in single.php (or elsewhere)?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.