Last active
February 18, 2018 22:45
-
-
Save thierrypigot/a085cff65542f4f8802c892ff16c3ab7 to your computer and use it in GitHub Desktop.
Get all entries for WordPress attachments on attachment archive page
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 | |
add_filter( 'register_post_type_args', 'tp_change_attachment_post_type_args', 10, 2 ); | |
function tp_change_attachment_post_type_args($args, $post_type){ | |
if( 'attachment' == $post_type ){ | |
$args['has_archive'] = true; | |
$args['rewrite'] = array( 'slug' => 'media' ); | |
} | |
return $args; | |
} | |
add_action( 'pre_get_posts', 'tp_get_all_posts_attachment' ); | |
function tp_get_all_posts_attachment( $query ) { | |
if( !is_admin() && is_post_type_archive('attachment') && 'attachment' == $query->get('post_type') ) | |
{ | |
$query->set( 'posts_per_page', -1 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment