add_filter('dynamic_sidebar_params', 'my_dynamic_sidebar_params');
function my_dynamic_sidebar_params( $params ) {
if (is_admin()){
return $params;
}
$widget_id = $params[0]['widget_id'];
if (get_field("widget_page", 'widget_'. $widget_id)){
$pages_id = get_field("widget_page", 'widget_'. $widget_id);
$pages_array = array('page' => $pages_id);
$params = array_merge($params, $pages_array);
if (is_singular()){
$id = get_the_ID();
$name = in_array($id, $params['page']);
}
}
if (get_field("widget_category", 'widget_'. $widget_id)){
$categories_id = get_field("widget_category", 'widget_'. $widget_id);
$categories_array = array('category' => $categories_id);
$params = array_merge($params, $categories_array);
if(is_category())
{
$id = get_the_category()[0]->cat_ID;
$name = in_array($id, $params['category']);
}
}
if(!$name){
return false;
};
return $params;
}