Forums

curl request in functions.php always outputs in index.php (2 posts)

  1. otaku_coder
    Member
    Posted 1 year ago #

    I have the following code in my functions.php file

    function read_tumblr_content() {
    	$sk_social_tumblr = get_option('social_tumblr');
    	$url = "http://".$social_tumblr.".tumblr.com/api/read/json";
    
    	if(function_exists("curl_version")) {
    		$c = curl_init();
    		curl_setopt($c, CURLOPT_URL, $url);
    		curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 2);
    		curl_setopt($c, CURLOUT_RETURNTRANSFER, 1);
    		$output = curl_exec($c);
    		curl_close($c);
    	}
    	else {
    		$output = "error: cannot fetch feed";
    	}
    
    	$output = "test";
    	return $output;
    }

    But when I simply call it from my template index.php like this:

    $myvar = read_tumblr_content();

    I keep getting the complete json string output in my browser, even though I've overridden the output to "test". Any help would be appreciated.

  2. otaku_coder
    Member
    Posted 1 year ago #

    Still having issues with this. Have tried it outside of wordpress and the code worked without any issues.

Topic Closed

This topic has been closed to new replies.

About this Topic