Make CPT Private by default

Support MB Custom Post Type Make CPT Private by default

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32632
    shmaltzshmaltz
    Participant

    Is it possible to make an entire CPT (all posts and archive) "Private"?

    I only want these posts/archive visible on the frontend by the admin/editors, and for all others, I want it to show a 404, just like a standard private post does.

    Is this possible?

    Thanks

    #32657
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can use a custom code to set the post status to private when creating/updating a post. For example

    function force_type_private( $post ) {
        if ($post['post_type'] == 'my_post_type')
        $post['post_status'] = 'private';
        return $post;
    }
    add_filter( 'wp_insert_post_data', 'force_type_private' );

    https://wordpress.org/support/article/post-status/

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