I found a solution; use pre_get_posts:
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;
}
Related Posts:
- How can I add an Author filter to the Media Library?
- Filter media library items by size
- Change text of Description in Image Library
- Ignore dots when searching in the media library?
- Filter Media by Featured on Admin
- Upload restrictions – upload_mimes – filter: Adding multiple MIMEs for a single extension and adding multiple extensions for a single MIME type?
- Media upload default title from file name
- Create a pre-filtered version of the Media Library
- Filter causing loss of _wp_attachment_metadata
- Filter Media by attached page or blog post in Library
- How to add custom media library mime icons?
- Code restricted to dashboard, running unexpectedly in the frontend (pre_get_post and admin-ajax.php)
- This code works, but breaks the media uploader. How do I integrate it in a way that won’t?
- Add custom options to the wplink dialog
- How to show page content in feed?
- remove_filter( ‘the_content’, ‘wpautop’ ); only for certain post types
- Valid characters for actions, hooks and filters
- How do I use the ‘http_request_host_is_external’ filter
- Is calling function_exists() faster or slower that apply_filters()
- Filtered query_vars becomes global. Why does this work?
- AJAX filter posts on click based on category
- Can I add custom meta for each image uploaded via media-upload.php?
- How do I know if author field was changed on post save?
- Alter only the page title, not the post titles within
- Load different template file when condition met?
- Looking for a hook to add attachment information to the media library tab
- Some questions regarding filter
- Problem getting single_template filter to work – I want to serve a different single.php file for posts in a certain category
- Too many actions/filters!
- Which hook is fired when inserting media into a post
- How can override a add_filter of a plugin?
- Adding Filter Conditionally Per Page ID
- Nested calls the the_content filter
- How to change domain used when pinging sites
- return values from hooks do_action and apply_filters, which is better
- Is it possible to track down Actions and Filters?
- Return a custom value in a function added to an action hook
- Using Conditional Statement in functions.php
- get_title without filter(the_title)
- Adding id and class to the search input in WordPress search form
- Multiple filters for wp_get_archive
- Filter and modify entry-footer link in twentyseventeen
- Function the_content not working
- Is there a filter called ‘network_admin_init’?
- Break out of wordpress filter
- Manipulating show_on_front, page_on_front, page_for_posts and template hierarchy
- Are there actions or filters I can use for Ajax calls?
- Custom view counts not updating correctly
- Using wp_handle_upload() to Direct Specific Path by Using $overrides
- WP Filter to change the URL of an Anchor wrapping the last gallery image
- Gutenberg – Add align controls to a custom block
- To add a custom filter based on a meta field
- How to create Woocommerce Product Filter Widget [closed]
- Add default user field to WooCommerce checkout [closed]
- Filtering Comment Reply Links (comment_reply_link_args) for “infinite replies” in nested comments
- Create Search Form to Filter Through Terms
- Formatting get_post content doesn’t allow JS content to function properly
- How can I change the email that is inside the default email texts of wordpress?
- How to filter link?
- Conditional does not work with add_filter
- Modify message displayed on post save
- Something is filtering my shortcodes… Can’t figure out what
- Pass debug_backtrace() in WordPress filter
- I need to hook and change language of facebook sdk
- change “missing attachment” text functions.php
- Use has_filter on comment_post
- Shorten the title length
- Problem with Class, Filters and Callbacks
- Renaming wordpress login and get new password button
- Search a title word through query_posts (not the exact match)
- Parse a shortcode differently based on on what it’s nested in
- return get_the_tag_list with whitespace removed
- Elementor Image Hover + Filter Grid [closed]
- How to redirect template_directory to subdomain relativ url?
- How do I add tags to entire comments, not just their text
- Scanning for custom embed and prefetching
- Remove and replace woocommerce add to cart button [closed]
- add_filter( ‘the_title’ gets through this if statement twice
- Changing the category for existing Gutenberg blocks
- Filter Post Title without affecting screen-reader-text
- Replace a specific URL on all apperances on the Website (Maybe a filter?)
- Modify WordPress Page Title ()
- How to add lazy field in content endpoint using Gutenberg blocks
- how to use apply filter for Class?
- How can I see exactly what arguments are being passed through a filter so that I may modify them?
- Re-order search results with posts_orderby filter and post meta value
- Set Microsoft Word links to open in new window/tab
- WordPress get_avatar filter to match logins
- ‘the_content’ Filter delivers empty string with lengh (608)
- Testing requested query in pre_get_posts
- Output dynamic_sidebar_params in wp_head
- How to sort posts according to meta value?
- Change shortcode output (filter?)
- How do I add a class to all sidebars to let a Google Custom Search Engine know not to index the content?
- Updating User Profile on Registration
- remove_filter excerpt_more from a plugin class
- Why does using excerpt_more filter change link location?
- Can you call a filter hook by “add_action”?
- Why isn’t this add_filter function working as expected?
- Adding filter to the Contact Form 7 response