1

This question already has an answer here:

I am trying to add custom menu widget to the sidebar. I am not working on wordpress directly, but I am using an xml-rpc calls to manage worpdress site (it is possible via http://wordpress.org/extend/plugins/extended-xml-rpc-api/ plugin). I am trying to achieve this using wp_set_sidebars_widgets function (I think its a proper way). First I am calling wp_get_sidebars_widgets to receive list of active sidebars and widgets. It gives me an array like that:

Array ( [wp_inactive_widgets] => Array ( [0] => archives-2 [1] => meta-2 [2] => search-2 [3] => categories-2 [4] => recent-posts-2 [5] => recent-comments-2 [6] => nav_menu-2 [7] => nav_menu-3 [8] => nav_menu-4 ) [sidebar-1] => Array ( ) [footer-1] => Array ( ) [footer-2] => Array ( ) [footer-3] => Array ( ) )

Now I am adding nav_menu-2 value to sidebar-1, so array looks like:

Array ( [wp_inactive_widgets] => Array ( [0] => archives-2 [1] => meta-2 [2] => search-2 [3] => categories-2 [4] => recent-posts-2 [5] => recent-comments-2 [6] => nav_menu-2 [7] => nav_menu-3 [8] => nav_menu-4 ) [sidebar-1] => Array ( [0] => nav_menu-2 ) [footer-1] => Array ( ) [footer-2] => Array ( ) [footer-3] => Array ( ) )

Now Im sending this array with wp_set_sidebars_widgets and problem is, that on wordpress Ive got 8 inactive sidebars instead of custom menu in sidebar-1. Calling wp_get_sidebars_widgets gives me now an array:

Array ( [wp_inactive_widgets] => Array ( [0] => archives-2 [1] => meta-2 [2] => search-2 [3] => categories-2 [4] => recent-posts-2 [5] => recent-comments-2 [6] => nav_menu-2 [7] => nav_menu-3 [8] => nav_menu-4 ) [1] => meta-2 [2] => search-2 [3] => categories-2 [4] => recent-posts-2 [5] => recent-comments-2 [6] => nav_menu-2 [7] => nav_menu-3 [8] => nav_menu-4 )

Its What Im doing wrong? Maybe someone knows another way to add custom menu to sidebar?

marked as duplicate by fuxia Feb 23 '13 at 17:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Did you read this answer? – fuxia Feb 22 '13 at 21:36
  • Thank you toscho. I have read that answer before, but i didnt noticed on that function update_option("sidebars_widgets",$active_widgets). This is answer for my question. If You want to turn on widget in your sidebar, you just have to make some code like this: '$active_widget = get_option("sidebars_widgets"); $active_widget["sidebar-1"][] = "nav_menu-2"; update_option("sidebars_widgets",$active_widgets);' Thank you toscho again. – bigwolk Feb 23 '13 at 16:38

Browse other questions tagged or ask your own question.