在“管理所有帖子”页面中显示一个特定类别的帖子(edit.php?post_type=post
) 您需要通过筛选连接term\\u relationships表posts_join
并通过筛选添加where子句posts_where
.
例如:。
add_filter( \'posts_join\', \'hide_attachments_wpquery_join\' );
function hide_attachments_wpquery_join( $join, \\WP_Query $query ) {
global $wpdb;
if( is_admin() && $query->query[\'post_type\'] == "post" ) {
$join .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
}
return $join;
}
add_filter( \'posts_where\', \'hide_attachments_wpquery_where\' );
function hide_attachments_wpquery_where( $where, \\WP_Query $query ) {
global $wpdb;
if( is_admin() && $query->query[\'post_type\'] == "post" ) {
// change 6 with your category/term id
$where .= " AND ( $wpdb->term_relationships.term_taxonomy_id IN (6) )";
}
return $where;
}