因此,每当我尝试在url中使用fetch_feed时,比如下面的url,我就会得到"WP HTTP错误: cURL错误28:在30070毫秒后超时的操作,接收到0字节“,但是当我在url上使用普通的cURL得到一个响应时。因此,我只能在Fetch Feed中得出结论。谁有更好的办法来解决这个问题?
include_once( ABSPATH . WPINC . '/feed.php' );
$feed_url = 'https://www.cbc.ca/podcasting/includes/frontburner.xml';
$rss = fetch_feed( $feed_url );
var_dump($rss);编辑:我在fetch_feed函数中做了一些调查,当我注释掉它时,发现它起了作用
$feed->set_file_class( 'WP_SimplePie_File' );可能是什么原因?是否可以在主题文件中进行此更改,以便在更新wordpress时不会更改?
发布于 2020-12-30 09:52:33
也许只有我们,但似乎您需要设置一个用户代理,而不是存储在SIMPLEPIE_USERAGENT常量中的默认用户代理,使用fetch_feed(),您可以使用wp_feed_options钩子来设置一个自定义用户代理--或者没有一个也适用于我。
工作实例:
add_action( 'wp_feed_options', function ( $feed ) {
$feed->set_useragent( 'MyPlugin/1.0' ); // works
$feed->set_useragent( $_SERVER['HTTP_USER_AGENT'] ); // works
$feed->set_useragent( '' ); // empty; worked for me..
// You can also try increasing the timeout, but the default one (10 seconds)
// worked fine for me.
$feed->set_timeout( 15 );
} );https://wordpress.stackexchange.com/questions/380615
复制相似问题