对于仍然关注这个问题的人来说,brasofilo的解决方案很好,但有些功能无法工作(搜索、每页帖子数、批量操作等)。解决方案:而不是pre_get_posts
您应该通过挂接到来修改sql查询posts_where
. 下面是为我完成这项工作的代码示例:
add_filter( \'posts_where\', \'mirmic_search_where\' );
function mirmic_search_where( $where ) {
global $pagenow, $wpdb;
if( \'edit.php\' == $pagenow && ( get_query_var(\'post_type\') && \'wszystkieposty\' == get_query_var(\'post_type\') ) ) {
$stringToReplace = "trnf_posts.post_type = \'wszystkieposty\'";
$replaceWith = "trnf_posts.post_type IN (\'infobus\', \'infoair\', \'inforail\', \'infotram\', \'infoship\', \'infoair\', \'infobike\')";
$where = str_replace($stringToReplace, $replaceWith, $where );
}
return $where;
}
function mirmic_wszystkieposty_distinct( $where ){
global $pagenow, $wpdb;
if ( is_admin() && $pagenow==\'edit.php\' && $_GET[\'post_type\']==\'wszystkieposty\') {
return "DISTINCT";
}
return $where;
}
add_filter( \'posts_distinct\', \'mirmic_wszystkieposty_distinct\' );
显示其他帖子类型的自定义帖子类型的slug为
wszystkieposty
. 相应地更改它。此行列出了要显示的其他帖子类型:
$replaceWith = "trnf_posts.post_type IN (\'infobus\', \'infoair\', \'inforail\', \'infotram\', \'infoship\', \'infoair\', \'infobike\')";