Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
Last active March 2, 2016 21:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgestephanis/8f3061a47bb81fb54f5e to your computer and use it in GitHub Desktop.
Save georgestephanis/8f3061a47bb81fb54f5e to your computer and use it in GitHub Desktop.
<?php
/**
* Media Grid:
* Filter out any videopress video posters that we've downloaded,
* so that they don't seem to display twice.
*/
add_filter( 'ajax_query_attachments_args', 'videopress_ajax_query_attachments_args' );
function videopress_ajax_query_attachments_args( $args ) {
$meta_query = array(
array(
'key' => 'videopress_poster_image',
'compare' => 'NOT EXISTS',
),
);
// If there was already a meta query, let's AND it via
// nesting it with our new one. No need to specify the
// relation, as it defaults to AND.
if ( ! empty( $args['meta_query'] ) ) {
$meta_query[] = $args['meta_query'];
}
$args['meta_query'] = $meta_query;
return $args;
}
/**
* Media List:
* Do the same as ^^ but for the list view.
*/
add_action( 'pre_get_posts', 'videopress_media_list_table_query' );
function videopress_media_list_table_query( $query ) {
if ( is_admin() && $query->is_main_query() && ( 'upload' === get_current_screen()->id ) ) {
$meta_query = array(
array(
'key' => 'videopress_poster_image',
'compare' => 'NOT EXISTS',
),
);
if ( $old_meta_query = $query->get( 'meta_query' ) ) {
$meta_query[] = $old_meta_query;
}
$query->set( 'meta_query', $meta_query );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment