WordPress.org

Ready to get started?Download WordPress

Forums

Category update - is failing (3 posts)

  1. rajrin
    Member
    Posted 6 years ago #

    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

  2. rajrin
    Member
    Posted 6 years ago #

    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);

  3. Michael Torbert
    WordPress Virtuoso
    Posted 6 years ago #

    rajrin, set this to resolved please.

Topic Closed

This topic has been closed to new replies.

About this Topic