我正在使用此函数从google获取imnages URL
function getGoogleImg($k)
{
$url = "http://images.google.com/images?as_q=##query##&hl=it&imgtbs=z&btnG=Cerca+con+Google&as_epq=&as_oq=&as_eq=&imgtype=&imgsz=m&imgw=&imgh=&imgar=&as_filetype=&imgc=&as_sitesearch=&as_rights=&safe=images&as_st=y";
$web_page = file_get_contents( str_replace("##query##",urlencode($k), $url ));
$tieni = stristr($web_page,"dyn.setResults(");
$tieni = str_replace( "dyn.setResults(","", str_replace(stristr($tieni,");"),"",$tieni) );
$tieni = str_replace("[]","",$tieni);
$m = preg_split("/[\\[\\]]/",$tieni);
$x = array();
for($i=0;$i<count($m);$i++)
{
$m[$i] = str_replace("/imgres?imgurl\\\\x3d","",$m[$i]);
$m[$i] = str_replace(stristr($m[$i],"\\\\x26imgrefurl"),"",$m[$i]);
$m[$i] = preg_replace("/^\\"/i","",$m[$i]);
$m[$i] = preg_replace("/^,/i","",$m[$i]);
if ($m[$i]!="")
array_push($x,$m[$i]);
}
return $x;
}
之后,我想添加图片url后元我使用此功能添加后元 function add_image_to_save_post($post_ID)
{
if ( !wp_is_post_revision($post_id) )
{
$title = $_POST[\'post_title\'];
$image = getGoogleImg ($title);
add_post_meta($post_ID, \'thumb\', $image[3], true);
}
}
add_action(\'wp_insert_post\', \'add_image_to_save_post\');
但当我点击链接add new post时,它会自动在数据库中添加空白的拇指键我只想为用户提供这个,所以只需添加文章,他们无需将图像添加到文章中,图像将自动获取,
有谁能给我建议这怎么可能
谢谢
穆罕默德·乌默尔