WordPress.org

Support

Support » WP-Advanced » Category update – is failing

Category update – is failing

  • I am using the following code to update the category for a give post_id, but its not working. Any ideas?

    /** I am allowing selection of only 1 category) **/
    ‘ $cat =
    $cats = array($cat,1);
    wp_set_post_categories($post_id,$cats);

    Thanks in advance,

    R

Viewing 2 replies - 1 through 2 (of 2 total)
  • OK _ Problem solved
    Instead of separately updating the category I am using the wp_update_post function…and it works.

    require ‘wp-blog-header.php’;

    $post_author = $_POST[‘post_author’];
    $cats = array();
    $x = $_POST[‘cat’];

    if ($x){
    foreach ($x as $t){
    //echo $t;

    array_push($cats,$t);
    }
    }

    $post_category = $cats;
    $post_datar = compact(‘ID’, ‘post_author’, ‘post_date’, ‘post_date_gmt’, ‘post_content’, ‘post_title’, ‘post_category’, ‘post_status’, ‘post_excerpt’, ‘post_name’);
    wp_update_post($post_datar);

    Michael Torbert
    WordPress Virtuoso

    @hallsofmontezuma

    rajrin, set this to resolved please.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Category update – is failing’ is closed to new replies.