Skip to content

Instantly share code, notes, and snippets.

@thierrypigot
Last active February 18, 2018 22:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thierrypigot/a085cff65542f4f8802c892ff16c3ab7 to your computer and use it in GitHub Desktop.
Save thierrypigot/a085cff65542f4f8802c892ff16c3ab7 to your computer and use it in GitHub Desktop.
Get all entries for WordPress attachments on attachment archive page
<?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