延迟发布Feed须谨慎
前阵子有人分享了一个延迟发布feed的技巧,在WordPress用户间广为流传。其原理就是利用WordPress的filter机制,发现当前的请求是Feed,即在查询条件中加一条,限制post的发布时间为五分钟之前(原文的代码escape太厉害了,直接复制有错误): [code lang=’php’]<?php /** puplish the content in the feed later $where ist default-var in WordPress (wp-includes/query.php) This function an a SQL-syntax */ function publish_later_on_feed($where) { global $wpdb; if ( is_feed() ) { // timestamp in WP-format $now = gmdate(‘Y-m-d H:i:s’); // value for wait; + device $wait = ‘5’; // integer // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff $device = ‘MINUTE’; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR // add SQL-sytax to default $where $where .= ” AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, ‘$now’) > $wait “; } return $where; } ...