Importing feeds with PHP

时间:2016-06-01 作者:Lara M.

我想创建一个可定制的代码,使用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 );
}

1 个回复
SO网友:setterGetter

Try changing foreach ($items as $item){ to foreach ($feed as $item){

相关推荐

Properly setting up a feed

我已尝试按照此处的说明设置提要:https://wordpress.org/support/article/wordpress-feeds/根据说明,https://sport-1a.de/category/Blog-Artikel/feed 应返回正确的进给。然而,我得到404页没有找到。尝试类别slug(https://sport-1a.de/category/blogpost/feed) 也没用。我怎样才能解决这个问题?