WordPress 作者存档页面显示自定义文章类型的内容

2024-01-19 16:40 小编

WordPress 默认会创建一个作者存档页面,例如 https://www.wpdaxue.com/author/cmhello 会显示该作者发布的所有文章,但是如果你的网站使用了自定义文章类型,默认情况下,在这个存档页面是不显示该作者发布的自定义文章类型的内容的。如果你希望它显示,可以在主题的 functions.php 添加下面的代码:

/** * WordPress 作者存档页面显示自定义文章类型的内容 * https://www.wpdaxue.com/custom-post-types-author-archives.html */function post_types_author_archives($query) {// 添加 questions 这个自定义文章类型到作者存档if ( $query->is_author ) $query->set( 'post_type', array('questions', 'post') );// 运行后移除这个挂载动作,防止无限执行 remove_action( 'pre_get_posts', 'post_types_author_archives' );}add_action( 'pre_get_posts', 'post_types_author_archives' );

请根据自己的实际,修改第 8 行的文章类型。


在线咨询 拨打电话

电话

13363039260

内部绝密传真282期

微信二维码