WordPress.org

Ready to get started?Download WordPress

Forums

How to update post cat before save_post (wp_set_post_categories only works once (3 posts)

  1. bsieders
    Member
    Posted 4 years ago #

    Hey guys,

    I'm trying to update categories of a post based on input in custom fields but wp_set_post_categories only works when the post is first created.

    I tried update_post_meta but that goes into an infinite loop because it calls the save_post action again.

    Is there anyway I can update the post categories directly through wpdb UPDATE?

    Thanks for your help,

    Balthazar

    //this only works when post is first created!
    function save_post_boxes($postID){
    $new_cats = array();
    array_push($_POST[$field]);
    save_custom_field($postID, $field, $_POST[$field]);
    wp_set_post_categories($postID, $new_cats);
    }
  2. bsieders
    Member
    Posted 4 years ago #

    Anyone? There has to be a way to do this ;/

  3. robanna
    Member
    Posted 4 years ago #

    I'm far from an expert but you may want to look at wp_update_post.
    http://codex.wordpress.org/Function_Reference/wp_update_post

Topic Closed

This topic has been closed to new replies.

About this Topic