questions

WordPress redirects to custom post single post page when trying to enter any matching letter

Rate this post

I have created a custom post type called institute. Here is the code for custom post type creation.

function register_institute_post_type()
{

    $labels = [
        "name" => __("Institute", "mgh"),
        "singular_name" => __("Institutes", "mgh"),
    ];

    $args = [
        "label" => __("Institutes", "mgh"),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => true,
        "show_ui" => true,
        "show_in_rest" => true,
        "rest_base" => "",
        "rest_controller_class" => "WP_REST_Posts_Controller",
        "has_archive" => false,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "delete_with_user" => false,
        "exclude_from_search" => false,
        "capability_type" => "post",
        'taxonomies' => array('category', 'post_tag'),
        "map_meta_cap" => true,
        "hierarchical" => false,
        "rewrite" => ["slug" => "institute", "with_front" => true],
        "query_var" => true,
        "supports" => ["title", "editor", "thumbnail", "custom-fields", "comments", "author", "page-attributes", "post-formats"],
    ];

    register_post_type("institute", $args);
}


add_action('init', 'register_institute_post_type');

It has created the institute post type. I have added posts to the custom post type. Now the problem is whenever I am trying any letters in the url it is automatically redirecting to the matching post details page for that institute post type.

So basically my initial setup url is like http://localhost/instututeportal but whenever I am trying anything like http://localhost/instututeportal/sa it is automatically redirects to

http://localhost/instututeportal/institute/sabanci-universitesi/

Here sabanci universitesi is a post from institute custom post type.

So can someone tell me how to show error message like 404 not found when someone tries to enter any random letters in the url? Any help and suggestions would be really appreciable.

 

✔️Solution:

Actually I had to make remove_filter redirect_canonical and it worked finally.

remove_filter( 'template_redirect', 'redirect_canonical' );

Leave a Reply

Your email address will not be published.

Back to top button