Hiding/removing the single post page of certain post types

Support MB Custom Post Type Hiding/removing the single post page of certain post types

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #49136
    AshAsh
    Participant

    How do I remove/hide the single post page from certain post types?
    Disabling "Public" option in CPT setting make the post type invisible to most query loop builder/post list plugins.
    This is not what I want.
    I want to create an archive page but I don't want to have its single post page.

    #49137
    AshAsh
    Participant

    I suppose disabling publicly_queryable would do?

    #49138
    AshAsh
    Participant

    No it didn't.
    Disabling publicly_queryable disables the archive page also.

    #49139
    PeterPeter
    Moderator

    Hello Ash,

    WordPress itself doesn't support a setting to remove the single post page but keep the archive page in the frontend. You can try to redirect the single post page to the archive page or another page, for example:

    add_action( 'template_redirect', function() {
        if ( is_singular( 'your_post_type' ) ) {
            wp_redirect( get_post_type_archive_link( 'your_post_type' ), 301 );
            exit;
        }
    } );
    #49174
    AshAsh
    Participant

    Thank you.
    Do you know how to disable the "rewrite"('rewrite'=false) of post type in Meta Box?

    #49175
    PeterPeter
    Moderator

    Hello,

    There isn't an option to set rewrite to false with UI. You can use the PHP code to register the post type and set it to false. For some advanced or dynamic cases, you will need to use the PHP code instead of using UI.

    Following the documentation
    https://developer.wordpress.org/reference/functions/register_post_type/#parameters
    https://docs.metabox.io/extensions/mb-custom-post-type/#getting-php-code

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.