I currently have a Multisite with 2 sites.
From the secondary site get_term_by()
works to retrieve terms from the primary site, but get_terms()
does not.
I'm using switch_to_blog(1);
but I get object(WP_Error)#1316 (2) { ["errors"]=> array(1) { ["invalid_taxonomy"]=> array(1) { [0]=> string(16) "Invalid taxonomy" } } ["error_data"]=> array(0) { } }
when I run get_terms()
Is there a way around this?
I currently have a Multisite with 2 sites.
From the secondary site get_term_by()
works to retrieve terms from the primary site, but get_terms()
does not.
I'm using switch_to_blog(1);
but I get object(WP_Error)#1316 (2) { ["errors"]=> array(1) { ["invalid_taxonomy"]=> array(1) { [0]=> string(16) "Invalid taxonomy" } } ["error_data"]=> array(0) { } }
when I run get_terms()
Is there a way around this?
Share Improve this question asked Dec 26, 2015 at 9:34 Austin BiggsAustin Biggs 3843 silver badges19 bronze badges 1- I think this link will help you. It has similar question. Please check answer: http://wordpress.stackexchange/questions/189035/get-all-terms-inside-a-specific-taxonomy-in-a-multisite – Prasad Nevase Commented Dec 26, 2015 at 9:49
1 Answer
Reset to default 1I figured out the answer, which seems to be an issue with WordPress.
Using get_terms() to get terms from another site WORKS, BUT A TAXONOMY BY THE SAME NAME MUST BE PRESENT ON THE SUBSITE YOU'RE WORKING FROM.
Below is my code (working):
switch_to_blog(1);
$taxonomy = array( 'taxonomy_name' );
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'exclude' => array(),
'exclude_tree' => array(),
'include' => array(),
'number' => '',
'fields' => 'all',
);
$terms = get_terms( $taxonomy, $args );
var_dump($terms);
restore_current_blog();
UPDATE: I've submitted a WP bug to Trac https://core.trac.wordpress/ticket/35231#ticket