这些功能有什么问题?
我正在为一个电视wordpress网站(www.canal-en-vivo.com)工作几个php函数,它根据频道Feed是直播还是根据频道Feed改变了发布到草稿的帖子(即频道)的状态,或者不。我把以下两个函数放在一起,但它们似乎不起作用。你们可以看看通用的代码结构,并告诉我,如果你看到结构有点奇怪吗?这些功能有什么问题?
该功能确定饲料是否是通过检查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;
}
而这个函数运行的SQL查询其改变状态基于先前的功能是否返回$每个岗位结果是活的或不活泼的。
// 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());
}
}
}
关于这些功能可能出错的任何想法帮派?
尝试这种情况:
在LiveOrNot()函数删除行
global $result;
而在RunChannelLiveQuery(),取代
LiveOrNot($feedurlstr);
通过
$result = LiveOrNot($feedurlstr);
虽然这不是必需的,但您可能希望使用Wordpress API来更新发布状态
我实际上遇到了SQL查询的一些问题:'你的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在''wp_posts'SET'post_status'='draft'WHERE'post_id'='2263''第1行附近使用正确的语法。使用Wordpress API ... – Alberto 2011-03-17 20:49:56
是的,绝对是一个很好的建议。 – 2011-03-17 21:11:17
冷若冰霜,感谢您的帮助!我做了更改,但我收到以下SQL错误:'您的SQL语法中有错误;检查与您的MySQL服务器版本相对应的手册,以便在''wp_posts'SET'post_status'='draft'WHERE'post_id'='2263''第1行附近使用正确的语法任何想法? – Alberto 2011-03-17 20:20:58
您不应该在表名和字段名称周围添加单引号。只有使用反引号('')是可能的。然后,你的第一个查询字符串应该看起来像“”UPDATE wp_posts SET post_status ='publish'WHERE post_id ='$ id'“'。查看MySQL手册获取更多细节。 – 2011-03-17 20:49:53
这是正确的冷霜。现在它声称DB中没有post_id列'Unknown'列'post_id'in'子句'Odd ... – Alberto 2011-03-17 20:54:59