WordPress widgets – where and how they are saved in database

In this article, I will tell you how WordPress widgets stored in {prefix}_options table as key/value pair when you set widget in a sidebar.

Options are sidebars_widgets and widget_{widget_ID} .

In this article, I will tell you how WordPress widgets stored in {prefix}_options table as key/value pair when you set widget in a sidebar.

sidebars_widgets and widget_{widget_ID}  are the options.

See below is the array which is stored in the serializing format in sidebars_widgets option key.

    [wp_inactive_widgets] => Array
            [0] => meta-2

    [sidebar-1] => Array
            [0] => search-2
            [1] => recent-posts-2
            [2] => recent-comments-2
            [3] => archives-2
            [4] => categories-2
            [5] => recent-posts-3

    [sidebar-2] => Array
            [0] => calendar-3

    [array_version] => 3

wp_inactive_widgets contain all inactive widgets. You can inactivate widgets by drag it to Inactive Widgets area.

Inactive Widgets


sidebar-1 (Primary Sidebar) and sidebar-2 (Footer Sidebar) contain active widgets set by the user. 

Note: sidebar slug and name will be different based on your theme.

recent-posts is the widget ID of Recent Posts widget. If you use the same widget multiple times then widget ID postfix by a numeric value. Fox example, In above array, I use Recent Posts widget twice so their IDs are  recent-posts-2 and recent-posts-3.

In this way, you will get which sidebar contain which widgets. Now you have a question like where widgets settings will store. So answer is, all widgets settings stored in widget_{widget_ID} option key in {prefix}_options table.

Below is the output for Recent Posts settings stored in widget_recent-posts option key.

    [2] => Array  // recent-posts-2
            [title] => 
            [number] => 5

    [3] => Array  // recent-posts-3
            [title] => Test title
            [number] => 10
            [show_date] => 1

    [_multiwidget] => 1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.