
wallpaper.php
By: a guest on
Jun 30th, 2012 | syntax:
None | size: 1.42 KB | hits: 198 | expires: Never
<form action="" method='POST'>
<input type="text" name="keyword" placeholder="keyword" />
<button name='submit' value="submit">Submit</button>
</form>
<?php
if($_POST['submit'])
{
$query = $_POST['keyword'];
$query = str_replace(' ','%20',$query);
$url = "http://api.bing.net/json.aspx?AppId=01B352A888B29AE34D58B17E7C1317F9317F2714&Query=$query&Sources=image";
$wallpaper = file_get_contents($url);
$wallpaper = json_decode($wallpaper);
$wallpaper = $wallpaper->SearchResponse->Image;
$posttitle = $wallpaper->Results;
$posttitle = $posttitle[0];
$posttitle = $posttitle->Title;
$content = '';
foreach($wallpaper->Results as $item)
{
$title = $item->Title ;
$url = $item->MediaUrl;
$content .= "<img src='$url' />" . "<br />";
$content .= $title . "<br />";
$content .= $item->Width ." x ". $item->Height . " px";
}
// mulai mengenal fungsi insert post
$my_post = array(
'post_title' => $posttitle,
'post_content' => $content,
'post_status' => 'publish',
'post_author' => 1,
);
wp_insert_post( $my_post );
}
?>