fill the wp_posts table

  • Unknown's avatar

    Hi,
    I’d like to migrate my redmine’s forum to my bbpress forum. I’ve noticed that my entries of bbpress (forums, topics, replies) were on my wp_posts table. I’d like to can fill the table to add new forums, topics, replies on my forum bbpress. But I found this page explaining that I should better use a specific PHP function to add entries in this table : http://codex.wordpress.org/Function_Reference/wp_insert_post

    When I try to add entries in the table with INSERT INTO requests, the forums are added, but it doesn’t work for the topics. :(

    When I try to use the wp_insert_post PHP function to fill my table from a page located on the root directory of WordPress, it doesn’t work.

    <?php 
    
    /** Sets up the WordPress Environment. */
    require( dirname(__FILE__) . '/wp-load.php' );
    
    require( dirname( __FILE__ ) . '/wp-blog-header.php' );
    
    if ( is_object( $wp_object_cache ) )
    	$wp_object_cache->cache_enabled = false;
    
    // Fix for page title
    $wp_query->is_404 = false;
    
    do_action( 'activate_header' );
    
    /**
     * Adds an action hook specific to this page that fires on wp_head
     *
     * @since MU
     */
    function do_activate_header() {
        /**
         * Fires before the Site Activation page is loaded, but on the wp_head action.
         *
         * @since 3.0.0
         */
        do_action( 'activate_wp_head' );
    }
    add_action( 'wp_head', 'do_activate_header' );
    
    // include_once("C:wampwwwwp-blog-header.php"); // Permet d'accéder à la fonction
    
    // ------------------- CONNEXION A LA TABLE TEMPORAIRE -----------------
    
    $PARAM_hote='localhost'; // le chemin vers le serveur
    $PARAM_port='3306';
    $PARAM_nom_bd='bd_name'; // le nom de votre base de données
    $PARAM_utilisateur='root'; // nom d'utilisateur pour se connecter
    $PARAM_mot_passe=''; // mot de passe de l'utilisateur pour se connecter
    $connexion = new PDO('mysql:host='.$PARAM_hote.';port='.$PARAM_port.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe);
    
    // Gestion des erreurs
    try
    {
            $connexion = new PDO('mysql:host='.$PARAM_hote.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe);
    }
    
    catch(Exception $e)
    {
            echo 'Erreur : '.$e->getMessage().'<br />';
            echo 'N° : '.$e->getCode();
    }
    ?>
    
    <?php // ---------------------- On va chercher les informations ----------------------
    $resultats=$connexion->query("SELECT * FROM wp_posts ORDER BY ID DESC LIMIT 0,1"); // on va chercher tous les champs de la table
    $resultats->setFetchMode(PDO::FETCH_OBJ); // on dit qu'on veut que le résultat soit récupérable sous forme d'objet
    while( $ligne = $resultats->fetch() ) // on récupère la liste des enregistrements de la table
    {
    // Réception des données en POST
    $post = array(
      'ID'             => $ligne->ID,  // Are you updating an existing post?
      'post_author'    => $ligne->post_author, // The user ID number of the author. Default is the current user ID.
      'post_date'      => $ligne->post_date, // [ Y-m-d H:i:s ], // The time post was made.
      'post_date_gmt'  => $ligne->post_date_gmt, // [ Y-m-d H:i:s ], // The time post was made, in GMT.
      'post_content'   => $ligne->post_content, // The full text of the post.
      'post_title'     => $ligne->post_title, // The title of your post.
      'post_excerpt'   => $ligne->post_excerpt, // For all your post excerpt needs.
      'post_status'    => $ligne->post_status, // Default 'draft'.
      'comment_status' => $ligne->comment_status, // Default is the option 'default_comment_status', or 'closed'.
      'ping_status'    => $ligne->ping_status, // Pingbacks or trackbacks allowed. Default is the option 'default_ping_status'.
      'post_password'  => $ligne->post_password, // Password for post, if any. Default empty string.
      'post_name'      => $ligne->post_name, // The name (slug) for your post
      'to_ping'        => $ligne->to_ping, // Space or carriage return-separated list of URLs to ping. Default empty string.
      'pinged'         => $ligne->pinged, // Space or carriage return-separated list of URLs that have been pinged. Default empty string.
      'post_modified'         => $ligne->post_modified,
      'post_modified_gmt'         => $ligne->post_modified_gmt,
      'post_content_filtered' => $ligne->post_content_filtered, // Skip this and let WordPress handle it, usually.
      'post_parent'    => $ligne->post_parent, // Sets the parent of the new post, if any. Default 0.
      'guid'           => $ligne->guid, // Skip this and let WordPress handle it, usually.
      'menu_order'     => $ligne->menu_order, // If new post is a page, sets the order in which it should appear in supported menus. Default 0.
      'post_type'      => $ligne->post_type, // Default 'post'.
      'post_mime_type'  => $ligne->post_mime_type, //[ <string> ] // Requires name of template file, eg template.php. Default empty.
      'comment_count'  => $ligne->comment_count, //[ <string> ] // Requires name of template file, eg template.php. Default empty.
    
    // C'est champs ne sont pas en base mais je préfère les conserver pour la fonction.
      'post_category'  => $ligne->post_category, // [ array(<category id>, ...) ] // Default empty.
      'tags_input'     => $ligne->tags_input, // [ '<tag>, <tag>, ...' | array ] // Default empty.
      'tax_input'      => $ligne->tax_input, // [ array( <taxonomy> => <array | string> ) ] // For custom taxonomies. Default empty.
      'page_template'  => $ligne->page_template, //[ <string> ] // Requires name of template file, eg template.php. Default empty.
     );  
    
    		$post_id = wp_insert_post($post, $wp_error ); // Exécution de l'array
    		// Remarque : Avec wp_insert_post, $wp_error n'est pas obligatoire.
    }
    $resultats->closeCursor(); // on ferme le curseur des résultats
    ?>

    I already ask the french support, but they do not know how to do.

    Thanks.

    The blog I need help with is: (visible only to logged in users)

  • The topic ‘fill the wp_posts table’ is closed to new replies.