Title: Plugin overrules core code, probable fix included
Last modified: January 4, 2017

---

# Plugin overrules core code, probable fix included

 *  Resolved [Internetbureau Clearsite](https://wordpress.org/support/users/clearsite/)
 * (@clearsite)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/plugin-overrules-core-code-probable-fix-included/)
 * Hi. I noticed that the plugin overrules the default wp_ajax_query-attachments
   action handler. (had me running in circles for a few hours). Though it works 
   like a charm, I foresee possible problems when WordPress decides to change the
   way the handler works, or changes the output of it.
 * Instead of overruling the entire function, perhaps it would be better to just
   alter the query with a filter on `ajax_query_attachments_args` .
 * Preliminary tests show this working perfectly, responding identically to your
   original code, perhaps you would like to evaluate and incorporate?
 * the change:
    remove the `wp_ajax_query-attachments` handler in the plugin add
   the following code (based on 1.5.3 version of the plugin, I added some comments
   for you to explain what I did, should be removed or changed in production)
 *     ```
       	function wpmediacategory_ajax_query_attachments_args($query) {
       		# grab original query, the given query has already been filtered by wordpress
       		$taxquery = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
   
       		# the original magic; but now on our own copy of the query object
       		$taxonomies = get_object_taxonomies( 'attachment', 'names' );
       		$taxquery = array_intersect_key( $taxquery, array_flip( $taxonomies ) );
   
       		# merge our query into the wordpress query
       		$query = array_merge($query, $taxquery);
   
       		# more of the original magic of the plugin, copied without 
       		# alterations from version 1.5.3
       		$query['tax_query'] = array( 'relation' => 'AND' );
   
       		foreach ( $taxonomies as $taxonomy ) {
       			if ( isset( $query[$taxonomy] ) && is_numeric( $query[$taxonomy] ) ) {
       				array_push( $query['tax_query'], array(
       					'taxonomy' => $taxonomy,
       					'field'    => 'id',
       					'terms'    => $query[$taxonomy]
       				));
       			}
       			unset ( $query[$taxonomy] );
       		}
   
       		return $query;
       	}
       	add_filter('ajax_query_attachments_args', 'wpmediacategory_ajax_query_attachments_args');
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Author [jeffrey-wp](https://wordpress.org/support/users/jeffrey-wp/)
 * (@jeffrey-wp)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/plugin-overrules-core-code-probable-fix-included/#post-8738873)
 * Hi,
    Thank you for pointing that out, it’s fixed as of version 1.5.4. And I made
   a thank you for you in the changelog.

Viewing 1 replies (of 1 total)

The topic ‘Plugin overrules core code, probable fix included’ is closed to new replies.

 * ![](https://ps.w.org/wp-media-library-categories/assets/icon-256x256.gif?rev=
   2658310)
 * [Media Library Categories](https://wordpress.org/plugins/wp-media-library-categories/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-media-library-categories/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-media-library-categories/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-media-library-categories/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-media-library-categories/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-media-library-categories/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [jeffrey-wp](https://wordpress.org/support/users/jeffrey-wp/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/plugin-overrules-core-code-probable-fix-included/#post-8738873)
 * Status: resolved