PHP 30
Remove attachment from main query and set url to ID By timo on 13th September 2018 12:09:40 PM
  1.  
  2. function wpd_attachment_link( $link, $post_id ){
  3.         $post = get_post( $post_id );
  4.         return home_url( '/images/' . $post->ID );
  5. }
  6. add_filter( 'attachment_link', 'wpd_attachment_link', 20, 2 );
  7.  
  8. function rewrite_post_types_for_mainquery( $query ) {
  9.         if ( $query->is_main_query() ) {
  10.                 $post_types = $query->query_vars['post_type'];
  11.                 if (($key = array_search('attachment', $post_types)) !== false) {
  12.                         unset($post_types[$key]);
  13.                 }
  14.                 $query->query_vars['post_type'] = $post_types;
  15.         }
  16. }
  17. if( !is_admin() ) {
  18.         add_action( 'pre_get_posts', 'rewrite_post_types_for_mainquery' );
  19. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.