好的,所以我找到了一個解決方案,但它看起來像一個黑客。如果有人知道更好的東西...
我的側邊欄的ID是「主頁」和我所有的控件的ID開始與我的前綴,nd_home_
:
global $wp_registered_sidebars, $wp_registered_widgets;
ob_start();
dynamic_sidebar('homepage'); //my sidebar id is 'homepage'
$sidebar_contents = ob_get_clean();
$widgetidspart1 = explode('nd_home_',$sidebar_contents); //my widgets ids start with nd_home_
for ($i = 1; $i < count($widgetidspart1); $i++) {
$widgetidspart2 = explode('" ', $widgetidspart1[$i]);
$widgetids[] = $widgetidspart2[0]; //id without nd_home_
}
//add nd_home_ to every widget id
foreach ($widgetids as $id) {
$widgetids_total[] = 'nd_home_' . $id;
}
//now I have all the ids in $widgetids_total. I can get the widget data:
foreach($widgetids_total as $id) {
$option_name = $wp_registered_widgets[$id]['callback'][0]->option_name;
$key = $wp_registered_widgets[$id]['params'][0]['number'];
$widget_data = get_option($option_name);
$data[] = $widget_data[$key];
}
//$data contains my widgets data