Skip Navigation

[Résolu] Global Taxonomy for Multisite

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
Create global taxonomies in a multisite shared across all sites of the network.

Solution:
This is not supported by Toolset, and no solutions can be readily found when searching. Some discussion of the problems appears below, but no solution.

This support ticket is created Il y a 5 années et 7 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par julieP Il y a 5 années et 7 mois.

Assisté par: Nigel.

Auteur
Publications
#1240217

I'd like to be able to have just one set of tables for taxonomies on a multisite install.

I've created the taxonomies for the post type on the blog and I'm using this snippet to get the values from the main tables:-

add_action( 'init', 'ts4_change_tax_terms_table', 0 ); 
add_action( 'switch_blog', 'ts4_change_tax_terms_table', 0 );
function ts4_change_tax_terms_table() {

    global $wpdb;
    
    $wpdb->terms = $wpdb->base_prefix . 'terms'; 
    $wpdb->term_taxonomy = $wpdb->base_prefix . 'term_taxonomy';

}

The values are available on CRED forms and are saved in the posts created.

In the search View, the values are available in the pick lists but when a value is selected, it's not shown/populated in the field to enable the search. Any ideas why this might be please?

#1240369

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi Julie

I need to set up a multisite test site to do some testing, I'll get back to you...

#1240409

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi Julie

I looked into this a little, but I didn't get too far, and I don't think I can go much further as this is really custom development work.

First point to note is that in your code you are updating the locations of the terms and term_taxonomy table but are missing other relevant tables.

I made a stab at updating your code (in a slightly more generic form):

function tssupp_global_taxomomies(){

	global $wpdb;

	if ( $wpdb->prefix != $wpdb->base_prefix ){

		$wpdb->terms = str_replace( $wpdb->prefix, $wpdb->base_prefix, $wpdb->terms );
		$wpdb->term_relationships = str_replace( $wpdb->prefix, $wpdb->base_prefix, $wpdb->term_relationships );
		$wpdb->term_taxonomy = str_replace( $wpdb->prefix, $wpdb->base_prefix, $wpdb->term_taxonomy );
		$wpdb->termmeta = str_replace( $wpdb->prefix, $wpdb->base_prefix, $wpdb->termmeta );
	}
}
add_action( 'init', 'tssupp_global_taxomomies' );

Echoing out $wpdb I can see that on a subsite the table names are successfully being updated in $wpdb.

But when navigating in the WordPress backend between the sites and adding terms etc. this is not functionally effective.

If you want to trick WordPress about the location of the taxonomy tables you need to do it in all circumstances for it to behave as intended and not have functional gaps and for it to work with plugins, such as but not limited to Toolset.

And I think the base problem in that case is that the init hook is too late for this.

Have a look at the hooks sequence: lien caché

You need the code to run very early, before other plugins, so I think the best place to try would be in an mu-plugin.

But even then it may not work.

If that's the case I can't really help any further as it's an unsupported feature that you would need to file a request for: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1240690

I have to confess the snippet isn't something I have written but what you say makes total sense.

Thank you for taking the time to look into a bit further; your revised snippet gives me something to work on. If all else fails I'll just abandon the idea!