• Resolved globalmanager46

    (@globalmanager46)


    Hello,

    I use your plugin for 2 different CPT. Actually all posts should be stay in private status. I have found a code thats working well for 1 CPT, but i do not find the right way to do it for 2 CPT.

    Here is the code i used for the first CPT and its posts to let it private everytime :

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

    Do you know how to add the second CPT to make it works for the both CPT ?

    Thanks a lot in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Try this out. You’ll want to fill in the array with the actual post type slugs you have.

    function force_type_private($post)
    {
    	if ( $post['post_status'] == 'trash' ) {
    		return $post;
    	}
    
    	$post_types = [
    		'my_custom_cpt',
    		'my_other_cpt',
    		'a_third_cpt',
    	];
    
        if ( ! in_array( $post['post_type'], $post_types ) ) {
            return $post;
        }
        
        $post['post_status'] = 'private';
        return $post;
    
    }
    add_filter('wp_insert_post_data', 'force_type_private');
    Thread Starter globalmanager46

    (@globalmanager46)

    Hi Michael,

    Awesome its working perfectly. Thanks a lot for your support

    Best Regards

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘CPT in Private’ is closed to new replies.