• Resolved Looic

    (@looic)


    Hi All,
    I am using a PHP script to manually create some posts into my WordPress :

    <?php
    require_once('/my/path/to/wp/wp-load.php');
    
    echo "Inserting post...";
    
    // ...
    // My geek stuff
    // ...
    
    $post = array(
      'ID' => $post_id,
      'comment_status' => 'open',
      'ping_status' =>  'closed' ,
      'post_author' => 0,
      'post_category' => $post_category_ary,
      'post_content' => $post_content,
      'post_excerpt' => $post_excerpt,
      'post_status' => 'publish',
      'post_title' => $post_title,
      'post_type' => 'post' );
    
    $post_id = wp_insert_post($post);
    if ($post_id == 0) {
            die('Can't insert or update post. Aborted.').
    }
    ?>

    And this script is invoked by :
    php ./myscript.php

    Now that I migrated to WP MU, this script doesn’t work anymore. there is no error message. The script seems to end execution at wp_load.php so that echo "Inserting post..."; is not reached. I tried to add switch_to_blog(6) after wp_load but nothing happens.

    Any idea on what to insert to call WP Multisite on commandline ?!

    Many thanks,
    Looic.

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

    (@looic)

    Hi,
    I am answering to myself if it can help somebody.

    Don’t know why but with Multisite, you have to set HTTP_HOST variable before starting the WordPress stuff. Do like this :

    $_SERVER[ 'HTTP_HOST' ] = 'www.yourdomain.com';
    require_once('/my/path/to/wp/wp-load.php');
    
    /*
    * ...
    * Your geek stuff ...
    */

    Have a good day 🙂
    Loic.

Viewing 1 replies (of 1 total)
  • The topic ‘Invoking WP Multisite in command line’ is closed to new replies.