我正在为电视wordpress网站(www.canal-en-vivo.com)工作几个php函数,根据频道提要是否有效,将帖子(即频道)的状态从已发布更改为草稿或不。我把以下两个函数放在一起,但它们似乎不起作用。您是否可以看一下通用代码结构,如果您看到结构奇怪的东西,请告诉我?
此功能通过检查URL“$ feedurlstr”
来确定Feed是否有效// 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查询,该查询根据前一个函数是返回$ result为live还是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());
}
}
}
关于这些功能团伙可能出现什么问题的任何想法?
答案 0 :(得分:1)
虽然不是必需的,但您可能希望使用Wordpress API来更新帖子状态
答案 1 :(得分:0)
试试这个:
在 LiveOrNot()功能中删除行
global $result;
在 RunChannelLiveQuery()中,替换
LiveOrNot($feedurlstr);
通过
$result = LiveOrNot($feedurlstr);