Question

I'm getting the feeling that adding Widgets via MySQL query is not as simple as I thought. I was under the impression all data is stored in the options table, but it seems like I was wrong.

Any idea how to place a widget via $wpdb? What data should be written down? And where?

Thanks!

Was it helpful?

Solution

Placing widgets via a MySQL or something MySQL abstracted via the global variable $wpdb that is an instance of the WPDB class is not trivial.

That's not because MySQL is something complicated or because $wpdb is useless at all but this has do something with the way the widget configuration is stored inside the mysql database options tables.

But there is always a work around. The nature of the widget configuration is stored inside the mysql database options tables. Just read the widgets configuration out of the option (get_option), edit it as you wish (use var_dump to inspect how that array is used) and then store it back into mysql via update_option.

That done you should be able to edit this "via mysql" (e.g. in the database) while making the settings of your wish.

This is quite a quick answer but it probably solves your issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top