Have a look at the $wpdb class, it does exactly what you want:
$myrows = $wpdb->get_results( "SELECT id, name FROM mytable" );
Try to avoid SQL queries for basic operations though. WordPress offers you many convenience functions for 80% of the tasks you would every come up with. They provide a nicer interface and preserve upwards compatibility.
For example to get posts from the DB you could use the WP_Query class or the get_posts() function.
Related Posts:
- Query in query for Widget
- Insert widgets into loop/custom query at every nth position
- Placing a widget with $wpdb query
- Creating a widget that displays the content of a page
- Reload widget with AJAX
- Limit number of Widgets in Sidebars
- How to load Widget javascript + css files only if used?
- check if registered sidebar is active & has widget content
- How to use wp_dequeue_style() for style enqueued in WP_Widget class
- Storing custom dashboard widget options in wordpress
- Programmatically edit the text of a widget
- Create a Widget Area in the Navigation Bar for the Genesis Theme Framework?
- Manual display of widget
- How to use stack flair on my site?
- Trigger Submit Event when Widget is added to Sidebar
- Ask user permission when activating a plugin
- List sidebars on a page
- How to enable / use new video / audio / images widgets in WordPress 4.8?
- How do i export the HTML from text widgets?
- Searching for a better Twitter widget
- Latest/Recent posts widget title link
- the_widget() and widget’s ID
- Widgets not expanding on wordpress 3.3 widget dashbord
- How to put Stack Exchange Flair as widget?
- How do i display the built-in gallery inside a widget?
- Forcing the title of a text widget on to a new line in the admin area
- Image Upload Widget Issue
- Wp Customizer event for when a new widget has been added
- Sidebar not show customizer!
- wp_register_sidebar_widget() disappered my Widgets submenu – what am I doing wrong?
- Display single widget
- Customizing wordpress default widgets?
- How to detect if query is runned from widget?
- How to make this change without changing the core? [duplicate]
- Add pagination to listing plugin
- how to put functions inside of widgets
- How to extend WP_Widget_Media
- Drafts widget for admin page
- Global $wpdb is not showing correct data with function call
- Text widget doesn’t save the content
- Post ID displayed instead of title [closed]
- Color picker in widget appears twice when added via the Customizer
- Hide widget (and white space) on specific resolution [closed]
- Adding Widgets to Draft Pages
- How do I pass the id of my widget to javascript in the form function?
- Widget – link to page rather than absolute url
- Programmatically add widgets to sidebars
- Are widgets meant to be used outside of sidebars?
- Is there a WordPress widget for my webpage?
- Validating widget’s configuration data on Admin page
- FTP Widget Location
- Turn off “This is the Primary Sidebar Widget Area” message
- Inserting Read More Tag in Widget
- dynamic sidebar in front page
- Adding a WordPress Widget to a settings page
- Display posts from category in post content?
- display widget checkbox selection on frontend
- Is there any tab widget plugin supporting third party widgets? [closed]
- Add footer widgets
- Widgets in WP 4.3 disappearing – How to fix?
- Making jQuery .change() event persistent after widget save
- Widget background images missing on second blog excerpt page
- How should I add a “widget” like element?
- modifying title (in dashboard) for different widget instances
- Removing side bar widgets from GovPress theme
- What conditional to use for dynamic sidebar check?
- How to test if the widgetized area has any widgets?
- Saving widget gets an undefined variable
- Trouble accessing a multidimensional array to add classes to default WordPress widgets
- Distinguish between different widgets of the same type
- links to Media Library content in sidebar per page
- Why is registering a sidebar for each page causing my sidebars to reset?
- How do I customize the positioning of WordPress widgets?
- widgets in footer?
- Quick Draft widget in weird place on dashboard after being re-added
- How can I remove WordPress element IDs and Class names in the HTML?
- Remove widgets on mobile front page without affecting desktop
- Widget display nothing
- How can I have sidebar widgets on Twenty Seventeen theme on all pages?
- Collapsible widgets [closed]
- Widget settings disappear after refresh
- How to display author meta in a sidebar widget
- Is it ok not to set widget in the main page of a one page WordPress Theme?
- How to get widget content in WordPress based on it’s ID?
- Recent Posts Widget URL / Domain change
- New Custom Widget Call a Different Widget Function
- Loading scripts only if a particular shortcode or widget is present
- Custom php Widget keeps disappearing from the front end
- Insert to wp_footer if widget is found in the sidebar
- Using javascript on the new widget preview / customizer page
- Filter CPT based on meta box value using Flexible Posts widget?
- Show or hide custom menu widget in side bar conditionally
- Custom tabs widget don’t work in google chrome, is blocked, do not change the tabs. Why?
- WordPress Hide Widget If $_Session Is Active?
- Widget which displays thumbnails, but links to urls?
- Recent posts with different class name for each post and a scrollbar?
- Problem on register/login widgets
- 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?