Created
August 7, 2012 17:50
-
-
Save pippinsplugins/3287764 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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