Skip to content

Instantly share code, notes, and snippets.

@pippinsplugins
Created August 7, 2012 17:50
Show Gist options
  • Save pippinsplugins/3287764 to your computer and use it in GitHub Desktop.
Save pippinsplugins/3287764 to your computer and use it in GitHub Desktop.
/**
* Retrieve current sidebar ID for a location.
*
* @since 2.0.0
*
* @param string $location the location for the sidebar
* @return string $id the id of the sidebar that should be shown
*/
if( ! function_exists( 'themeblvd_get_sidebar_id' ) ) {
function themeblvd_get_sidebar_id( $location ) {
// Innitiate assignments
$assignments = array();
// Get all the sidebars for this location and create
// a single array of just their assignments
$args = array(
'post_type' => 'tb_sidebar',
'numberposts' => -1,
'meta_key' => 'location',
'meta_value' => $location
);
$custom_sidebars = get_posts( $args );
if( $custom_sidebars ) {
foreach( $custom_sidebars as $sidebar ){
$current_assignments = get_post_meta( $sidebar->ID, 'assignments', true );
if( is_array( $current_assignments ) && ! empty ( $current_assignments ) ) {
foreach( $current_assignments as $key => $value ) {
$assignments[$key] = $value;
}
}
}
}
// Find the current custom sidebar with from assignments
return themeblvd_get_assigned_id( $assignments );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment