我想创建一个可定制的代码,使用wp cron在Wordpress中导入一些提要RSS。
我正在尝试,但它没有显示任何东西,有人能解释一下为什么吗?
<? php
add_action(\'feed_event\', \'feed_hourly\');
function feed_activation() {
if ( !wp_next_scheduled( \'feed_event\' ) ) {
wp_schedule_event(time(), \'hourly\', \'feed_event\');
}
}
add_action(\'wp\', \'feed_activation\');
function feed_hourly() {
$time = get_option(\'lastfeed\');
if(function_exists(\'fetch_feed\')){
$url = \'http://www.site/feed/\';
$feed = fetch_feed($url);
}
if($feed) {
foreach ($items as $item){
$titlepost = $item->get_title();
$description = $item->get_description();
$itemdate = $item->get_date();
if( $item->pubDate < $time) { } else {
$my_post = array(
\'post_title\' => $titlepost,
\'post_content\' => $description,
\'post_date\' => $itemdate,
\'post_status\' => \'publish\',
\'post_category\' => array(get_cat_ID(\'FEED\',\'Italia\' ))
);
wp_insert_post( $my_post );
}
}
}
feed_option( \'lastfeed\', $items[0]->pubDate );
}