Turn on and off custom post type from admin?

Is it possible to “deactivate” a custom post type and then later if you feel like using it again you can simple “activate” it again?

Related posts

1 comment

  1. Yes, custom post types are registered on the fly, on every request. So you can create an option, say active_custom_post_types and check for that before you register the post type.

    Pseudo-code:

    $possible_cpts = array( 'book', 'portfolio' );
    $active_cpts   = get_option( 'active_custom_post_types' );
    
    if ( ! empty ( $active_cpts ) && is_array( $active_cpts ) )
    {
        foreach ( $active_cpts as $cpt )
        {
             if ( in_array( $cpt, $possible_cpts ) )
                register_post_type( $cpt, get_args_from_somewhere() );
        }
    }
    

Comments are closed.