I've made an option of creating unlimited sidebars, then there is an option to select any desired sidebar from a select element, which is a custom meta field, in each category edit page. So far so good, everything works and every category displays the selected sidebar.
Now what i am trying to do is to output the same sidebar in every post (single.php) as in the category this post is assigned to.
Have anyone done something similar?
The code for outputting the sidebar in category page is:
<?php
if ( is_category() ){
$sidebar = get_post_meta( $post->ID, 'select_a_sidebar', true );
dynamic_sidebar( $sidebar );
}
?>