I am using this function to get imnages urls from google
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;
}
After that i want add image url to post meta i am using this function to add post meta
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');
But when i click on on link add new post its add autmatically blank thumb key in database
I just want this for users so just add articles they no need to add image to article image will fetch automatically,
Can anyone give me suggestion how this possible
Thanks
MOhammad Umer
global $post; $pos_id = $post->ID;, besides the$pos_idbeing an unused variable afterwards I don't thinkglobal $postcontains anything at that point, you already have the$post_IDfrom the action, what do you needglobal $post;for? – soulseekah Oct 18 '11 at 7:55die('Trying to get image...');at the very top of your function to see if it's even called? Also modify your question to reflect the current code you're working with, please. – soulseekah Oct 18 '11 at 9:12