Forums

wp_set_post_categories not working for me as should (2 posts)

  1. O_Breda
    Member
    Posted 3 years ago #

    Hello,

    I've tried to run a PHP file created by me.

    It has one purpose only: to set some categories to an existing post.

    I use (wrongly, it seems) this function: wp_set_post_categories

    Cand you plese guide me into one solution?

    See bellow my (not working) PHP file. I've put it in the Plugins folder, to allow me to run admin.php.

    <?php
    
    $cats = array ("cat1","cat3","cat2");  //these categories exist
    
    $admin = realpath(dirname(__FILE__) . '/../..'.'/wp-admin');   //this line works, no erros given
    chdir($admin);                                                    //this line works, no erros given
    require_once $admin . '/admin.php';                               //this line works, no erros given
    
    $id = intval(63);  //I use this function to make sure it's an integer value
    
    wp_set_post_categories($id, $cats);  //you got it, this doesn't work
    
    echo 'I got until here.';  //This text is printed on the screen
    
    ?>

    Any ideas welcome.

  2. O_Breda
    Member
    Posted 3 years ago #

    I think it might have to do with running the application as a Plugin. Anyone knows how to do that?

Topic Closed

This topic has been closed to new replies.

About this Topic