Hi,
I am a bit stumbled on how to get the Wordpress Custom fields feature to work through PHP. I have gotten for Wordpress to apply the custom fields to all the posts, however, am now a bit stumped on how to add a variable within the Custom fields code to be able to pull the real image URL. The end result I am trying to get is for the code to pull the image URL.
//curl function
function get_data($url){
$ch = curl_init();
$timeout = 25;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch); curl_close($ch);
return $data;
}
$queryul="SELECT * FROM ".$wpdb->prefix."db";
$film = $wpdb->get_row($queryul);
$from = $_GET['from'];
if($film!=NULL){
$link=$film->url;
$link=trim($link);
$data=$film->data;
$queryul2="DELETE FROM ".$wpdb->prefix."db WHERE url='$link'";
$wpdb->query($queryul2);
$data=trim($data);
$category=$film->category;
$category=trim($category);
$imdb_content = get_data($link);
// get Poster Url;
$pos=strpos($imdb_content,'Poster"');
$img_search = substr($imdb_content, 0, $pos);
substr($imdb_content, 0, $pos);
if($pos!=0) {
$pos1=strrpos($img_search,'src="');
$pos2=strpos($img_search,'"',$pos1+5);
$poster=substr($imdb_content,$pos1+5,$pos2-$pos1-5);
srand((float) microtime() * 10000000);
$indice=rand(1000,9999);
$where="posters/".$data."-".$indice.".jpg";
copy($poster,$where);
$where=get_option('home')."/admin/".$where;
add_action('publish_page', 'add_custom_field_automatically');
add_action('publish_post', 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
global $wpdb;
$thelink=$where
if(!wp_is_post_revision($post_ID)) {
add_post_meta($post_ID, 'image', $thelink, 'true');
}
}
Basically, I don’t get why $thelink is not pulling the data from $where, which should be the URL of the image link. What I am trying to edit is the last snippet of code (second box) to be able to get the correct image URL to input into the custom field. If anyone could advise what I am doing wrong, I am will feel very appreciative. I have spent several hours messing with it, and still am stumped. Any help would be greatly appreciated.
Thanks!