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?


Try this:

In LiveOrNot() function remove the line

global $result;

And in RunChannelLiveQuery() , replace

LiveOrNot($feedurlstr);

by

$result = LiveOrNot($feedurlstr);

尽管这不是必需的,但您可能希望使用Wordpress API来更新发布状态

链接地址: http://www.djcxy.com/p/69656.html

上一篇: 如何合并两个SQL查询以获取最新的WordPress博文和精选图片

下一篇: 这些功能有什么问题?