I would like in my plugin to make a custom post type only in admin. When I register my cpt, I do this :

$args = [
  'public' => false,
  'publicly_queryable' => false,
register_post_type( $post_type, $args );

It seems to be correct but when I edit it, I can still modify the visibility.

How can I remove the visibility for this custom post type ?

  • Perhaps you take a look at post__not_in and use $wp_query. – Charles Dec 11 '19 at 14:11
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');

please try above code, I hope this will work for you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.