Querying in WordPress is done by using the the wpdb
variable. Be sure to always prepare your sql so WP can make it database safe.
Example:
global $wpdb;
$rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$wpdb->prefix}TABLE_NAME` WHERE `var` = %d", 1) );
Then you can loop through the data and output it as for example a table (table formatting not included).
foreach($rows as $row)
{
echo $row->post_title;
}
Please note that the SQL query above doesn’t work because it contains dummy data. Please change it so it fits your needs.
Related Posts:
- Change all http to https in mysql databse?
- WooCommerce – Query for ordered products
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Query WordPress database by registered date and role
- Select Multiple meta_value from WP DB; Single Query
- Advanced SELECT query with condtional statements
- Slow queries constantly getting stuck on WordPress database of ~100,000 posts
- Query multiple tables at once?
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- SQL query to set posts in bulk based on the post content
- Query Column of Specific ID from Database Table
- WordPress Database Query works in phpMyAdmin but not in the code
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- MySQL SELECT increment counter
- phpMyAdmin – Error > Incorrect format parameter?
- MySQL Database User: Which Privileges are needed?
- Why is my database import losing text widget data?
- Will it break my site if I delete all transient records in wp_options table?
- Please explain how WordPress works with MySQL character set and collation at a low level
- Reset Post IDs to less than 64bit integer
- WordPress database scalability from the code perspective
- Does WordPress use the InnoDB engine for MySQL by default?
- Can I use MariaDB instead of MySQL in wordpress?
- Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
- Split WP install between 2 databases?
- Inserting Post Meta From SQL
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- Why does dbDelta() not catch MysqlErrors?
- Is altering a default WordPress database table update safe?
- How to sort results from a custom database table
- Delete all post meta except featured image
- Custom DB_COLLATE (collation) value not working on fresh install?
- What causes the “max_user_connections” warning on WordPress frontend?
- what to do when your WordPress database is too large?
- WordPress and automated MySQL backups to a different host
- How Do I Merge Categories With phpMyAdmin
- Size article thumbnails and retrieve them directly from database
- WordPress site uses MyISAM, should I switch to InnoDB necessary?
- How to prevent WordPress from retrieving data for the last 10 posts in the database?
- Query from a different database than the default
- Which is more efficient? Using usermeta, or creating a new MySQL table?
- WordPress mysql table double prefixes
- Hook directly into query execution
- Create WP_Query to search for posts by their categories or their parent/child categories
- WordPress database import: Row size too large
- Why do mass updates to post_content shows in front end, but not in edit screen?
- Handling large N data in WordPress
- Is MariaDB’s Aria storage engine suitable for WordPress?
- Improve performance by removing unnecessary database queries
- Redirecting to old domain after migration website
- A MySQL DB within a MySQL DB
- How do I query wp_options for expired transient pairs with MySQL commands?
- Switching Databases in LocalHost
- cache specific data?
- Is there a way to recover the table wp_term_relationships?
- Trouble Migrating all data blog from WordPress.com to WordPress.org
- Unable to set a default serialized array using dbdelta()
- How Can I Put Meta_Compare in the Database-Query?
- WordPress running SQL query to update database from form
- How to fix database error duplicate entry
- Historic WordPress database connection
- Check if an option exists and get its value in one hit
- Why this query is not showing any result on wordpresss home page?
- How to display content from external db with relevant urls
- Why does changing Database Table Prefixes result in loss of content?
- Moving WordPress site to new domain – database import [duplicate]
- How to connect and insert data in database of wordpress?
- Buddypress avatar image in database [closed]
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- $wpdb->get_var – What value is returned when zero records are found?
- Installing local to live WP into subdirectory
- How can I query the db to access current post information?
- Only allow user to access a link once a year, based on their joining date
- Counting post and changing roles in mysql database. Query not code
- MSQL database wp_postmeta has meta key tve_revision
- Insert NULL value using prepare()
- I imported an restore an database and It shows #1067 – Invalid default value for ‘user_registered’
- “BS_” rows in postmeta table
- How can I find user role in Mysql?
- Featured image from custom to WordPress database
- Delete all users meta that named: user_avatar
- mySQL database size large, but tables size less
- How to optimise this database query?
- spambot registering without providing email or password, bypassing registration process
- After renaming MySQL database, I can no longer access my Blog page
- How To connect to the same WordPress database with different database user
- Possible to restore wordpress database from mysql56 and sqlite files?
- Get multisite count without php?
- Create a new table on the database and save parameters from a contact form
- Widgets with *internal* links do not display after database migration
- How do i get value from wp_postmeta?
- featured image not showing up with mysql_connect
- How to back-up a database on IIS
- database search feature
- Importing Concrete5 content to WordPress
- why you don’t Implement PDO for access every thing to database
- SQL query to rewrite all media URLs to end with .webp
- How do I find users by password?