• 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.

Viewing 1 replies (of 1 total)
  • Thread Starter O_Breda

    (@o_breda)

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

Viewing 1 replies (of 1 total)
  • The topic ‘wp_set_post_categories not working for me as should’ is closed to new replies.