Jump to content

Recommended Posts

Posted
$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!

Posted

That should solve the ProcessWire API side of the problem! Now I have to figure out how to join the comments into the record returned as `$article` in my code above…

Is that a LEFT JOIN?

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
  • Recently Browsing   0 members

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