WordPress.org

Ready to get started?Download WordPress

Forums

Functions to Change Post Status (1 post)

  1. Alberto
    Member
    Posted 3 years ago #

    Guys,

    I am working a couple of function for a TV Channel website (www.canal-en-vivo.com) which changes the status of posts (ie. channels) based on whether the feed is live or not. I put together the following two functions, but they don't seem to work. Would you guys take a peek at the general code structure and let me know if you see something weird:

    This function determines whether the feed is live or not by checking an URL "$feedurlstr"

    // This will be the function that determines whether given channel is live or not
    	function LiveOrNot($feedurlstr) {
    		global $result;
    		// create curl resource
    		$ch = curl_init();
    		// set url
    		curl_setopt($ch, CURLOPT_URL, $feedurlstr);
    		//return the transfer as a string
    		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    		// $output contains the output string
    		$output = curl_exec($ch);
    		// close curl resource to free up system resources
    		curl_close($ch);      
    
    		$string = "PP['channel_live'] = true";
    		if(strstr($output,$string)) {
    		$result = "live";
    		} else {
    		$result = "notlive";
    		}
    		return $result;
    	}

    And this function runs a SQL query which changes the status each post based on whether the previous function spits live or notlive.

    // Function that runs SQL query based on channel status
    	function RunChannelLiveQuery() {
    		global $key;
    		global $post_ids;
    		$key = 'feed';
    		$post_ids = array(2263, 2249); //this will change into a SQL query that pulls al the IDs
    
    		foreach ($post_ids as $id) {
    			$feedurl = get_post_custom_values($key, $id);
    			// turns $feedurl into string
    			$feedurlstr = implode($feedurl);
    			// Find whether feed is live or not
    			LiveOrNot($feedurlstr);
    
    			// Performs DB Query based on live or not
    			if ( $result == "live" ) {
    				mysql_query ("UPDATE 'wp_posts' SET 'post_status' = 'publish' WHERE 'post_id' = '$id'") or die(mysql_error());
    			}
    			if ( $result == "notlive" ) {
    				mysql_query ("UPDATE 'wp_posts' SET 'post_status' = 'draft' WHERE 'post_id' = '$id'") or die(mysql_error());
    			}
    		}
    	}

    Do you guys see something wrong with the structure of these functions? Any feedback would be awesome gang - thanks a ton!

Topic Closed

This topic has been closed to new replies.

About this Topic