• Hi,

    I have a small php script to import blog post from b2evolution to wordpress and using polylang.

    Currently, all posts are imported but nothing appears in the frontend blog because I don’t say witch table I must update to set the language for each post.

    What table can I update to set the language for each post ?

    My script

    function insert_wp_post($post, $idx, $prefix, $pdo) {
        
        $query = 'INSERT INTO ' .$prefix . 'posts(post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count)
                  VALUES(1, :date, :date_gmt, :content, :title, :excerpt, :status, :comment, :ping, :password, :name, :to_ping, :pinged, :modified, :modified_gmt, :content_filtered, :parent, :guid, :menu_order, :type, :mime_type, :comment_count)';
        
        $req = $pdo->prepare($query);
        
        $req->bindParam(':date', $post->post_datecreated);
        $date = Date('Y-m-d H:i:s', strtotime($post->post_datecreated . ' - 1 hour'));
        $req->bindParam(':date_gmt', $date);
        $content = $post->post_content ? $post->post_content : '...';
        $req->bindParam(':content', $content);
        $req->bindParam(':title', $post->post_title);
        $excerpt = $post->post_excerpt ? $post->post_excerpt : '';
        $req->bindParam(':excerpt', $excerpt);
        
        if($post->post_status == 'published') {
            
            $status = 'publish';
        }
        elseif($post->post_status == 'draft') {
            
            $status = 'draft';
        }
        else {
            
            $status = 'private';
        }
        
        $req->bindParam(':status', $status);
        $close = 'closed';
        $open = 'open';
        $req->bindParam(':comment', $open);
        $req->bindParam(':ping', $close);
        $empty = '';
        $req->bindParam(':password', $empty);
        $name = sanitize($post->post_title);
        $req->bindParam(':name', $name);
        $req->bindParam(':to_ping', $empty);
        $req->bindParam(':pinged', $empty);
        $req->bindParam(':modified', $post->post_datemodified);
        $date_modified = Date('Y-m-d H:i:s', strtotime($post->post_datemodified . ' - 1 hour'));
        $req->bindParam(':modified_gmt', $date_modified);
        $req->bindParam(':content_filtered', $empty);
        $zero = 0;
        $req->bindParam(':parent', $zero);  
        $guid = 'https://newvajra.localhost/?p=' . $idx;
        $req->bindParam(':guid', $guid);
        $req->bindParam(':menu_order', $zero);
        $article = 'post';
        $req->bindParam(':type', $article);
        $req->bindParam(':mime_type', $empty);
        $req->bindParam(':comment_count', $zero);
        
        if($req->execute()) {
            
            $req->closeCursor();
            
            $query = 'INSERT INTO ' .$prefix . 'term_relationships(object_id, term_taxonomy_id, term_order)
                  VALUES(:id, :taxonomy_id, :term_order)';
            
            $r = $pdo->prepare($query);
            
            $id = $pdo->lastInsertId();
            $r->bindParam(':id', $id);
            if($post->post_locale == 'fr-BE' || $post->post_locale == 'fr-FR') {   
                $taxonomy = 15;
            } else if($post->post_locale == 'nl-BE') {
                $taxonomy = 94;
            } else {
                $taxonomy = 1;
            }
            $r->bindParam(':taxonomy_id', $taxonomy);
            $r->bindParam(':term_order', $zero);
            
            if($r->execute()) {
                
                $r->closeCursor();
                
                return true;
            }
        }
        
        return false;
    }

    Thx in advance

  • The topic ‘import posts from b2evolution to wordpress’ is closed to new replies.