It seems that you can’t access to it. Please try add global $wpdb;
to your function.
UPDATE
For reference, in WordPress Codex you will find:
WordPress provides a global variable, $wpdb, which is an instantiation
of the class already set up to talk to the WordPress database. Always
use the global $wpdb variable. (Remember to globalize $wpdb before
using it in any custom functions.)
Related Posts:
- How do i export the HTML from text widgets?
- Proper approach to moving complete site from one domain to another AND preserve widgets
- WordPress database error – quick review
- Programmatically add widgets to sidebars
- changing wp-admin/widgets.php
- Text Widget creates a
- Get Widget Instance inside Widget
- Add the sidebar/widget editor to the post edit screen?
- WP_Widget deprecated error in WordPress V4.3
- What is the quickest way to make a widget?
- Changes in widget customizer not triggering ‘save and publish’
- How to Validate Widget Input
- Remove before_widget / after_widget content from Wp_Widget_Text
- Big side banners
- How to execute SQL SELECT query and see the results?
- Display specific widgets in different area’s around the page
- Need help adding additional controls to a custom widget Part 2
- How to add the widgets manually to the sidebar?
- How to check if widget has automatic title
- Display sidebar that created in functions.php
- Unable to save widget contents
- Image picker widget
- Use wp_enqueue_style based on user option in widget
- When you register a sidebar in WordPress, is it possible to choose in what order it appears in the admin
- How to enable “shift-click to edit this widget” functionality on a custom widget?
- dynamic_sidebar() returns false in admin section
- Moving comments section to left of content (Twenty Thirteen)
- Custom Tag Cloud widget missing tags
- How the widget can be run by shortcode
- add widgets to dashboard for easy access for clients?
- How to add new sidebar widget area to child theme?
- Uses Cases for the Calendar Widget
- Wrap all default widget into div tag
- Problem with widgets
- How to make multi -column, interesting home page in Weaver 2010?
- wp_editor is not rendering shortcode
- Recent Posts – Show all posts
- Widgets missing after update
- Dashboard Widgets – Add Admin Page With Same Functionality
- Debugging / displaying errors in WP_Widget->form()
- Help with custom widget options! (saving checkbox option)
- How to filter products using filter products by attribute widget and OR logic between different product attribute types?
- Can you target a widget_class in a register_sidebar?
- Default widgets assignment – isn’t working
- How to add custom widget above admin_footer
- How to create a ‘single’ category widget for woocommerce plugin [closed]
- Displaying info in a sidebar
- wp_get_attachment_image() not displaying post images even though wp_get_attachment_url() echo correct urls
- I have a widget area in my header. How can I have that display a different widget depending on what group is shown?
- change widget to display excerpt instead of content
- How do widgets access posts they should display?
- Remove links from meta widget
- How to register a widget when saving a post?
- How to make home widgets appear horizontally
- Using more widget in main page cause slow loading WordPress? [closed]
- add_action not working within widget() of WP_Wdiget
- WordPress custom widget undefined variable notice
- Multiple rows of footer widget areas
- How do I make the title of the following widget editable?
- Escape HTML on WP input
- how can i display all youtube videos from a users youtube account
- Link a widget or find the php that creates the widgets
- How to add Ajax to the default widget calendar to support next/previous months loading?
- Issue with checked() echoing on to page
- Add a widget to a static front page
- Last Update time in widget
- Register new widget
- Problem with WP_Query loop and search term
- How to use register_sidebar’s ‘before_widget’ unique id generator into its other parameters like ‘before_title’?
- Set a dashboard widget to the top?
- How to decorate WP_Widget_Text?
- After adding widget the style is messing up
- Widget title showing below widget
- Siderbar implementation with collapsible bootstrap cards
- Simple SCript Not Displayed in WIdth
- how to get value of a select box in custom widget wordpress
- Using the_widget Multiple Times
- Conditionally Load a Script if a Certain Widget is Shown on a Page
- Where to add a widget class?
- Does current page contain widget or sidebar
- Active Sidebar Conditional Question?
- Paginate recent posts widget
- Widget front-end fails to echo as expected from checkbox
- Adding Widgets to Reactor Theme (based on Foundation 4)
- Help me tidy up my widget code
- Neaten content — different widget or CSS change?
- Custom widget breaking widget section in admin menu
- Unique widget id in sidebar
- Taxonomies not showing in WP Dashboard Right Now widget
- trying to Change to wp_register_sidebar_widget
- How to delete Jetpack Widgets from the Widgets page in admin panel [closed]
- How to customize dynamic_sidebar rendering? [closed]
- Can’t use is_home in template-functions.php
- How can I order the “Woocommerce Products Widget” by the sales date? [closed]
- Widget does not work with WooCommerce enabled
- How to show WordPress Dashboard Widgets on Frontend?
- How can I add a toggle element into an image box element? [closed]
- Widget block editor: Unable to collect checkbox values inside widget update() method
- Theme Widget Area Defaults
- How to add the “page” post type to Recent Activity widget displayed in admin?