Hi all,
I'm still relatively new to the PW world and needed a little help.
I've been looking into how to import JSON into new pages and have managed to get that working fine (through help of others posts on the forum).
I've got it checking if the page exists (not sure if it's the right way), but am stuck when it comes to updating the page (if it exists).
Also, completely stuck when it comes to deleting the page -- if it's not in the JSON anymore.
Can anyone help me out/point me in the right direction?
<?php
$movies = json_decode(file_get_contents('http://www.omdbapi.com/?s=smart&page=1&apikey=xxxxxx'));
foreach ($movies->Search as $movie) {
$exists = $pages->get("name=$movie->imdbID");
if($exists->id) {
echo $exists->id . ' already exists <br>';
} else {
$p = new Page();
$p->template = 'single-movie';
$p->parent = wire('pages')->get('/movies/');
$p->name = $movie->imdbID;
$p->title = ucfirst($movie->Title);
$p->save();
// populate fields
$p->event_id = $movie->imdbID;
$p->movie_original_title = ucfirst($movie->Title);
$p->movie_image_url = $movie->Poster;
$p->save();
echo $p->title . ' added <br>';
}
}
?>