I'm making a mapping between page-id's and category-id's, that's being used several places.
However I read from this post, that one should never use global variables if one could avoid it. But I would argue that this would be smart to have as a global variable, so it's not a function that should be executed several time (and iterate over several ID's every time).
But I'm unsure how to do this. Here's what I got:
/**
* Should this be here, in order to make it global?
*/
$page_category_mapping = array();
global $page_category_mapping;
/**
* Building the mapping...
*
* Should this tage the $page_category_mapping
* as input?
*/
function build_page_category_mapping(){
// Going over all pages and maps them to a category
}
add_action( 'init', 'build_page_category_mapping' );
/**
* I assume this function should take the array as input, right?
*/
function a_funtion_that_uses_the_mapping( $page_category_mapping ){
echo '<pre';
print_r( $page_category_mapping );
echo '</pre';
}
add_shortcode( 'list_mapping', 'a_funtion_that_uses_the_mapping' );
wp_get_object_terms
to fetch the categories? WP already caches these things in memory, so if you're trying to improve performance with a global variable, you'll see no gainscategory.php
?