A Bit Stumbled on Something PHP/Wordpress Related


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;	
	$data = curl_exec($ch);	curl_close($ch);	
	return $data;

$queryul="SELECT * FROM ".$wpdb->prefix."db";
$film = $wpdb->get_row($queryul);
$from = $_GET['from'];

	$queryul2="DELETE FROM ".$wpdb->prefix."db WHERE url='$link'";
	$imdb_content = get_data($link);

	// get Poster Url;
	$img_search = substr($imdb_content, 0, $pos);
	substr($imdb_content, 0, $pos);
	if($pos!=0)	{
		srand((float) microtime() * 10000000);			
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;
	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.


$thelink=$where ;

Not sure if that is intentional, you are missing a semicolon on that line, should be showing you an error though …

Looks to me as though $where should be declared global too.

The ; was a mistake on my part on copy and pasting an older version of the code, but I don’t think it is the reason why it is not working.

Also, since $where pulls from both $data and $intice, do you believe setting these to be global would be the way to go?

Easy enough to test using trial and error:

//override your $where for a moment
$where = "a test";

// then

function add_custom_field_automatically($post_ID) { 
    global $wpdb; 

// uncomment out the line below and see what diff it makes
//    global $where; 

// commented out for the meantime
//    if(!wp_is_post_revision($post_ID)) { 
//        add_post_meta($post_ID, 'image', $thelink, 'true'); 
//    }