WordPress 技巧:把自定义日志类型添加到 Feed

如果你的 WordPress 和我一样使用了自定义日志类型(Custom Post Type),并且想把这个自定义日志类型的文章显示到 Feed 中,那么你需要在 functions.php 中加入下的代码:


add_filter('pre_get_posts', 'add_microblog_2_feed' );
function add_microblog_2_feed( $query ) {
	if ( is_feed()){
		$query->set('post_type', array( 'post', 'm'));
	}
	return $query;
}

其中这里的 m 是我爱水煮鱼微博的 Custom Post Type 的名称,如果你想吧 page 更新也放到 feed 中去,可以把上面改成 array( 'post', 'page')


©我爱水煮鱼,本站推荐使用的主机:阿里云,国外主机建议使用BlueHost

本站长期承接 WordPress 优化建站业务,请联系微信:「chenduopapa」。