WordPress.org

Ready to get started?Download WordPress

Forums

Remove public visibility entirely (5 posts)

  1. publicradio
    Member
    Posted 2 years ago #

    I have a couple custom post types that I don't want to ever be published publicly. I know that when you register a custom post type, you can set 'public' to 'false', but this simply prevents you from publishing at all.

    I would like to be able to publish these post types, but I will never set the visibility to 'public', and will probably never set it to 'password' either. Therefore, I want the only visibility option to be 'private' and all custom posts to be private by default.

    Can someone tell me if this is possible, and how to do it? Thanks.

  2. Marventus
    Member
    Posted 2 years ago #

    Hi.
    Here is an article that seems to address your issue (untested).
    Cheers!

  3. publicradio
    Member
    Posted 2 years ago #

    Thanks, I think it gets me halfway there:

    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');

    Except it only accepts privately published posts. So if you go to create a new post, it's immediately privately published. There are no drafts, and you can't move it to the trash.

    I'll try to tweak it from here,though. Thanks.

  4. publicradio
    Member
    Posted 2 years ago #

    This works a little better:

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

    It's the same as above, but is says if it's published, it's private. this preserves draft and trash functionality.

  5. Lithform
    Member
    Posted 1 year ago #

    This works great for private posts to remain in draft, thank you.

    This little change works for all Posts:

    /** Private posts all the way down */
    function force_type_private($post)
    {
        if ($post['post_type'] == 'is_singular' && $post['post_status'] == 'publish')
        $post['post_status'] = 'private';
        return $post;
    }
    add_filter('wp_insert_post_data', 'force_type_private');

Topic Closed

This topic has been closed to new replies.

About this Topic