向媒体库查询中添加分组依据的正确方法是什么?到目前为止,我所累的还没有发挥作用:
add_filter(\'posts_groupby \', \'limitMediaLibraryItems\', 10, 2 );
function limitMediaLibraryItems($groupby) {
if ( strpos( $_SERVER[ \'REQUEST_URI\' ], \'/wp-admin/upload.php\' ) !== false ) {
$groupby .= " guid";
}
return $groupby;
}
更新:也许正确的方法是使用ajax\\u query\\u attachments\\u args过滤器。这是如何实现的?
add_filter( \'ajax_query_attachments_args\', \'hide_duplicate_guids\', 10, 1 );
function hide_duplicate_guids( $query = array() ) {
$query[\'group by\'] = \'guid\';
return $query;
}
SO网友:AlanP
我找到了解决办法;使用pre\\u get\\u帖子:
add_action( \'pre_get_posts\', \'modify_attachments\' );
function modify_attachments( $query ) {
if ( is_admin() && strpos( $_SERVER[ \'REQUEST_URI\' ], \'admin-ajax.php\' ) !== false ) {
add_filter( \'posts_groupby\', \'group_attachments\' );
}
return $query;
}
function group_attachments( $groupby ) {
$groupby .= " guid";
return $groupby;
}