Jump to content

How To Import Comments Into Comments Field


johnstephens
 Share

Recommended Posts

$articles = database()->query('
    SELECT *
    FROM textpattern
    WHERE section="blog"
');

foreach($articles as $article) {
  $newArticle = new Page();
  $newArticle->template = 'blog-post';
  $newArticle->parent = pages()->get('/blog');
  $newArticle->title = $article['Title'];
  $newArticle->body = $article['Body_html'];

  // Add other content from query to $newArticle->{fields} here

  $newArticle->save();
}

I'm using something like the above to connect to a database, grab articles, and import them into ProcessWire.

The source database has comments for these articles in a table called `txp_discuss`, which uses the `parentid` field to link comments to their parent article's `id`.

I know I can associate that info with my `$article` items by editing the MySQL query, but I don't know how to pipe it in to a ProcessWire Comments field called `comments` that I added to the `blog-post` template I'm using. Does anyone have guidance to offer having done this before?

Thank you in advance!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...