Opened 9 years ago
Closed 9 years ago
#35231 closed defect (bug) (duplicate)
get_terms() doesn't work on Multisite
Reported by: | 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)
Note: See
TracTickets for help on using
tickets.
See #32526 & #20541
Ultimately this is an invalid use-case, Taxonomies must be registered during the pageload to be accessible.