WordPress 4.5 introduced to the world the
WP_Site class. WordPress 4.6 is going to help you query sites in your network using the new
What’s a site, really?
WordPress has a neat feature called “WordPress Multisite” which allows you to create multiple sites with just a single installation. With multisite enabled, you can create multiple independent sites that are not connected to each other by any means, or, create a “network” of sites which are directly related to each other. If you really want to take WordPress to the extreme, you can create a network of networks, which is a multi-level network containing other networks and each of those has it’s own sites. 🙂
A “site” is a single instance in the
wp_blogs DB table. A “site” can simply be the website created by WordPress, or a virtual website created as part of a network by the multisite feature.
As mentioned above, WordPress 4.5 introduced the
WP_Site class which introduces interactivity options with a site on a multisite network. The class can be used for retrieving site data as well as for setting it up.
As of WordPress 4.6, we can use the
WP_Site_Query class for querying sites from the database. This neat query class returns an array which contains a list of sites matching the search criteria (Each array entry being an instanced object of
The new Query class helps query sites the same way we currently query WordPress Posts, Users, Comments, Terms and other common components. It’s basically an easy way to filter down items from the database, without having to write custom code, while leveraging WordPress’ core APIs, such as the Cache API for instance.
Site Query Generator
Just like we did with other Query Generators, we created a new generator to help you get started using this cool new class. Introducing our new WP_Site_Query Generator! It a free generator open to the general public.
Note that although our Site Query Generator simplifies the class internals, it’s an advanced tool. You should have deep multisite knowledge whenever interacting with sites on your network.
Should you have any questions, suggestions or marriage proposals — let me know in the comments section below.