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?
- Is there a way to override only a portion of the function print_media_templates defined in wp-includes\media-template.php?
- Why is the change in my query not taking into account
- How to edit dashboard search posts button texts for my CPT?
- Conditional Image Sizes for Use via Theme Customizer Upload Only
- wp_mail works with add_action(‘save_post’, …) but not an ajax action
- add_filter with retrieve_password_message() not working in plugin, but works in functions.php
- How to check if a protected hook is hooked?
- Add a div of content within the_content after a certain block
- Gutenberg Block – Post Featured Image Filter Hook
- Can i use multiple ‘the_content’ filters?
- Is it possible to put the add-filter()-hook into a function?
- How can I return shortcode output to the top of the content?
- separate categories with comma and srounded by single quote
- Filter for when the post is updated
- Prevent add_filter being applied to wp-admin pages
- Translate custom order status through a filter?
- Using preg_replace() with the_content filter
- term_link filter gives less atributes
- Filter a pluggable function
- apply_filters(‘get_the_content’, $content) + Except
- Filter everything from content except output of a shortcode
- Add mime types with plugin
- Filter media upload attachment meta
- Filter have_posts()/ the_post()
- Is there a way to globallly apply esc_html( … ) to all inputs and anchors to filter out XSS markup?
- Filter wp_redirect() to stop redirect under certain condition
- Filter get_page_by_path()
- Handle multiple parameters in filter
- How to add filter in custom rss feed
- Want to use wp_get_current_user() in query filter
- WP 4.5 hide core customizer sections
- Echo string in admin panel footer beside version no
- How to change default text for specific post type
- Add PHP code after title in single post pages?
- Apply wordpress filter checking category
- Custom nav walker: How to acces the $args parameter?
- How to stop the deduction in “wp_term_taxonomy” count, when the post is deleted?
- How To Get Search Term and Use in Function
- alternative to the_content filter
- How to set a filter search for categories of blog posts in wordpress
- Same URL for portfolio and for a page creates 404 error. Is there any filter that i can use for a child page?
- Filter widget_posts_args not working
- How to pass a variable between filter/action functions?
- Filter the title to only affect the_title() template function
- How can I filter the comment action links so that I can display the actions links based on user capabilities?
- Adding link options in insert/edit link dialog window
- how to unescape wordpress output
- How can I limit access to uploaded media depending on the logged in user’s user role?
- Database & Post Search
- login_url filter creates permanent wp-admin -> wp-login redirection loop
- How can I filter same content in page
- How can I change the button text of a custom widget?
- WordPress Tag Cloud Filter Prevents Widget HTML from loading
- Using add_filters() , apply_filter(), add_action() and do_action() in extending a plugin
- the_content filter not working when Jetpack activated. Any idea?
- Adding Filter | Page Title | Template | Why the_title affecting on menu?
- gettext filter does nothing
- Hide a specific post from Archive Feed
- Restrict access to custom post type and filter from every query
- Why none of xmlrpc filters work
- How to use the filter ‘widget_text’ to a particular text widget with id
- Filter for wp_embed_handler_youtube not working
- Post Type Upload Directory – {post_type}_upload_dir filter
- Custom xmlrpc request does not pass parameters?
- Hook into ‘when user logs in’ [persistent login]
- Filter on widget-title does not work with custom links
- Custom registration field to SQL database
- Problem with shortcodes in external file
- WordPress URL rewrite problem
- How to reset/remove added filters ‘posts_join’ and ‘posts_orderby’ after the loop is completed?
- How to turn this customized core function into a filter/action in functions.php?
- Which hook should be used in this case?
- Categorize posts on a page o the basis of category of other post on the same page
- manage_users_custom_columns filter not firing callback functions
- Conditionally including JS based on whether ACF field is set [closed]
- How to use apply_filters(‘get_calendar’) to change get_calendar() output?
- How to add custom HTML attribute to reusable block div in WordPress admin
- Add a filter conditionally based on frontpage
- Using two posts_orderby add_filter makes conflict
- custom post filter based on Visitors country
- How to correctly override a filter?
- Is there a way to check if the ‘wp_sitemaps_enabled’ is true or false?
- Block Gutenberg Editor manually by User Roles with a Filter with code
- Changing upload directory temporarily
- How to use add_filter to add the extra data to existing array?
- Is it possible to modify a WP search query to return results for private pages when not logged in?
- Accidentally created 2 pages, same name. Changing permalink on one changes both