Forcing two or more custom post type to be private

I registered a new custom post type and forced it to be private, but now I need to use three custom post type. I registered the second one, but I don't know hot to set the code to force the second one.

Here is the code I used to force the first CPT ('my_post_type1')

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

How can I force the second ('my_post_type2')?

Thank you very much

Topic private custom-post-types Wordpress

Category Web


You can add multiple compared condition variable in single if condition using logical OR operator.

For more knowledge of Logical condition click

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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.