开发者

What is wrong with these functions?

I am working a couple of php functions for a TV wordpress website (www.canal-en-vivo.com) which changes the status of posts (ie. channels) from Published to Draft based on whether the channel 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 with the structure?

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

// This function determines whether a given post/channel is live or not 
// based on whether url $feedurlstr has $string in it.

    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 returns $result as live or notlive.

// Function runs SQL query based on channel status $result

    function RunChannelLiveQuery() {
        global $key;
        global $post_ids;
        $key = 'feed';
        // This array includes the Post ID to be checked
        $post_ids = array(2263, 2249); 

        foreach ($post_ids as $id) {
        // Wordpress function to pull value out of a "custom field" - spits URL
            $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());
            }
        }
    }

Any ideas on what might be wrong with these functions gang?


While it isn't essential, you might want to use the Wordpress API for updating the post status


Try this:

In LiveOrNot() function remove the line

global $result;

And in RunChannelLiveQuery(), replace

LiveOrNot($feedurlstr);

by

$result = LiveOrNot($feedurlstr);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜