global categories - Share specific categories in wordpress multisite
I have a wordpress multisite network. So I want to share just some categories between subsites.
Topic globals categories multisite Wordpress
Category Web
I have a wordpress multisite network. So I want to share just some categories between subsites.
Topic globals categories multisite Wordpress
Category Web
Here is a solution I found-
// even before any taxonmy/terms are initialized, we reset the tables
add_action( 'init', 'the_dramatist_change_tax_terms_table', 0 );
// on blog switching, we need to reset it again, so it does not use current blog's tax/terms only
// it works both on switch/restore blog
add_action( 'switch_blog', 'the_dramatist_change_tax_terms_table', 0 );
function the_dramatist_change_tax_terms_table(){
global $wpdb;
// change terms table to use main site's
$wpdb->terms = $wpdb->base_prefix . 'terms';
// change taxonomy table to use main site's taxonomy table
$wpdb->term_taxonomy = $wpdb->base_prefix . 'term_taxonomy';
// if you want to use a different sub sites table for sharing, you can replca e$wpdb->vbase_prefix with $wpdb->get_blog_prefix( $blog_id )
}
This code makes all the taxonomy terms( It is not taxonomy, just terms) global. I got it here. The terms can be added from any of the sub site and depending on the currently available taxonomy( registered taxonomy) of a sub site, the terms will be available there.
Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.