Forum Replies Created

Viewing 1 replies (of 1 total)
  • function remove_cpt_slug( $post_link, $post, $leavename ) {
     
        if ( 'games' != $post->post_type || 'publish' != $post->post_status ) {
            return $post_link;
        }
     
        $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
     
        return $post_link;
    }
    add_filter( 'post_type_link', 'remove_cpt_slug', 10, 3 );
    
    function gparse_request_trick( $query ) {
    
        // Only noop the main query
        if ( ! $query->is_main_query() )
            return;
    
        // Only noop our very specific rewrite rule match
        if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
            return;
        }
    
        // 'name' will be set if post permalinks are just post_name, otherwise the page rule will match
        if ( ! empty( $query->query['name'] ) ) {
            $query->set( 'post_type', array( 'post', 'page', 'games' ) );
        }
    }
    add_action( 'pre_get_posts', 'parse_request_trick' );
    
    • This reply was modified 9 years, 4 months ago by freehack.
    • This reply was modified 9 years, 4 months ago by freehack.
Viewing 1 replies (of 1 total)