Replies: 0
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');