Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#35231 closed defect (bug) (duplicate)

get_terms() doesn't work on Multisite

Reported by: austintbiggs's profile AustinTBiggs Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Taxonomy Keywords:
Focuses: multisite Cc:

Description

Today I found a bug within WordPress Multisite functions.

From a subsite I tried accessing the terms of a custom taxonomy on site #1. This worked using get_term_by(), but not with get_terms(). WordPress returns with "Invalid Taxonomy", however I knew the taxonomy existed.

In order to overcome this, I had to create a custom taxonomy on the subsite with the exact same name. Then WordPress successfully returned the terms from site #1.

Below is my code:

switch_to_blog(1);
								
$taxonomy = array( 'custom_taxonomy' );
						
$args = array(
	'hide_empty' => false, 
	'exclude' => array(), 
	'exclude_tree' => array(), 
	'include' => array(),
	'number' => '', 
	'fields' => 'all', 
); 
						
$terms = get_terms( $taxonomy, $args );
						
var_dump($terms);
						
restore_current_blog();

Change History (3)

#1 @AustinTBiggs
9 years ago

  • Severity changed from normal to major

#2 @swissspidy
9 years ago

  • Component changed from Networks and Sites to Taxonomy
  • Severity changed from major to normal

#3 @dd32
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

See #32526 & #20541

Ultimately this is an invalid use-case, Taxonomies must be registered during the pageload to be accessible.

Note: See TracTickets for help on using tickets.