Last active
March 2, 2016 21:37
-
-
Save georgestephanis/8f3061a47bb81fb54f5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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