Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Remove Slug From Custom Post Use Parent Post

$
0
0

Replies: 0

I am using this code to remove the slug from a custom post type. I cannot create a parent for that custom post type as it returns 404 error. Any assistance would be much appreciated!

function na_remove_slug( $post_link, $post, $leavename ) {
    if ( 'events' != $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', 'na_remove_slug', 10, 3 );

function na_parse_request( $query ) {
    if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
        return;
    }
    if ( ! empty( $query->query['name'] ) ) {
        $query->set( 'post_type', array( 'post', 'events', 'page' ) );
    }
}
add_action( 'pre_get_posts', 'na_parse_request' );
  • This topic was modified 14 minutes ago by scubageorge.
  • This topic was modified 13 minutes ago by scubageorge.
  • This topic was modified 12 minutes ago by scubageorge.

Viewing all articles
Browse latest Browse all 59525

Trending Articles