I have a father blog / main blog inside a multisite that has a specific taxonomy with 20+ terms inside it. i just need a list of all the terms inside that taxonomy…
i dont mind quering using WPDB but just dont know to how to write it correctly or in any other way i tried use: “switch_to_blog” but that doesnt work when quering terms
Any suggestion?
i tried the: Multisite Global Terms plugin (doesnt work)…
EDIT (response to question in comment)
this is an example of switch_to_blog i tried:
function multisite_profession_select(){
switch_to_blog(1);
$taxonomies = array('rsitecat');
$args = array('hide_empty' => false);
$terms = get_terms($taxonomies, $args );
echo '<pre>';
print_r($terms);
echo '</pre>';
restore_current_blog();
}
The reponse i get:
WP_ERROR OBJECT
(
[ERRORS] => ARRAY
(
[INVALID_TAXONOMY] => ARRAY
(
[0] => INVALID TAXONOMY
)
)
[ERROR_DATA] => ARRAY
(
)
)
3 Answers
No way to do that in a “word press” way…
function multisite_profession_select(){
switch_to_blog(1);
$taxonomies = array('rsitecat');
$check_later = array();
global $wp_taxonomies;
foreach($taxonomies as $taxonomy){
if (isset($wp_taxonomies[$taxonomy])){
$check_later[$taxonomy] = false;
} else {
$wp_taxonomies[$taxonomy] = true;
$check_later[$taxonomy] = true;
}
}
$args = array('hide_empty' => false);
$terms = get_terms($taxonomies, $args );
echo '<pre>';
print_r($terms);
echo '</pre>';
if (isset($check_later))
foreach($check_later as $taxonomy => $unset)
if ($unset == true)
unset($wp_taxonomies[$taxonomy]);
restore_current_blog();
}
WP will check if Taxonomy exists, but on multisite blog, its only switching $table_prefix but not actually switching to blog. In this fixed code – it should trick WP to think that taxonomy registred and retrive a term from a mu blog tables. after request – you killing fake taxonomy ghosts.
P/S/
I didn’t test code.