PHP
30
Remove attachment from main query and set url to ID By timo on 13th September 2018 12:09:40 PM
- function wpd_attachment_link( $link, $post_id ){
- $post = get_post( $post_id );
- return home_url( '/images/' . $post->ID );
- }
- add_filter( 'attachment_link', 'wpd_attachment_link', 20, 2 );
- function rewrite_post_types_for_mainquery( $query ) {
- if ( $query->is_main_query() ) {
- $post_types = $query->query_vars['post_type'];
- }
- $query->query_vars['post_type'] = $post_types;
- }
- }
- if( !is_admin() ) {
- add_action( 'pre_get_posts', 'rewrite_post_types_for_mainquery' );
- }
Recent Pastes