• Hello everybody! Is it possible to create custom post types at network level in a multisite? if yes, is it possible from a plugin?

    Currently, all the sites have the same custom post type that are been using as settings page. I need a new feature that allows me to configure these settings at network level, and all of the sites for that network could read that setting if they need. Otherwise, they could continue to use their own settings (custom post type at site level).

    I know I could use a setting page at network level for this, but it causes a high effort than a cpt at network level option, since I already have the cpt created and I only need to replicate the format.

    I created a new menu and submenu at network level using the network_admin_menu hook, but when I want to register the new custom post type using the init hook and register_post_type wordpress function….the custom post type is created in site level instead of network.

    Any idea?

    • This topic was modified 4 years, 2 months ago by James Huff. Reason: moved to Networking WordPress since this is a multisite question
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Sorry for the slow reply. There isn’t really a network level post type, they’re all registered at site level. You can ensure a post type will be available for all sites by registering from a must-use plugin. The issue is if the registration code needs data from the DB. Saving option values from a network screen ends up in the main site’s options table and will not be directly available in sub-sites. You can use switch_to_blog() to get to the main site’s options table. Use restore_current_blog() to switch back.

    There’s not a good place in the default DB to store arbitrary network level data. To avoid the need to switch blogs back and forth, you could create a custom table for the purpose and use the global $wpdb object to access it.

    Your registration code should apply default values in case there are no saved options yet. Once something is saved, the correct post type registration will be used on any subsequent requests.

Viewing 1 replies (of 1 total)

The topic ‘Create custom post types at network level in a multisite’ is closed to new replies.