When you use $wpdb->prepare
the placeholder %s
is replaced with something between quotes, so, your query becomes:
"SELECT * FROM 'wp_users' WHERE ID = 1"
but table names in SQL queries must not be wrapped in quotes. So, the right way is:
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->users} WHERE ID = %d", 1 );
$results = $wpdb->get_results($sql);
Note that this may not work because nothing assure that exists an user with the id = 1. (Actually someone discourages to have user with ID = 1 for security reason).
If you want to pick first user is better to use something like:
$user = $wpdb->get_row( "SELECT * FROM {$wpdb->users} ORDER BY ID ASC LIMIT 1" );
In this way you get first user row, no matter what its ID is.
Related Posts:
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- phpMyAdmin – Error > Incorrect format parameter?
- Why is my database import losing text widget data?
- Get error messages when $wpdb->insert() returns false?
- Does dbDelta delete columns as well?
- Insert data in database using form
- how can get database name in wordpress?
- Special characters in WordPress UTF-8 [closed]
- Long option names fail silently?
- Upload files – total size limit – WordPress/Contact Form 7
- $wpdb variable throw this error Call to a member function get_results() on a non-object in
- Extend the wp_users table
- Relationship between performance and database size
- I have a problem with my WordPress DB after I tried to install multi-site
- Database sync between local and production
- WordPress and automated MySQL backups to a different host
- Scheduling posts in database
- Size article thumbnails and retrieve them directly from database
- Connect Second Database to WordPress
- Should I be able to run two different “close” code versions of wordpress with the same DB
- Query from a different database than the default
- Need of separate security plugins for both root and subfolder sites WordPress?
- Escaping / encoding data before insert into a database?
- how to store arrays into a database
- Error: SELECT SQL_CALC_FOUND_ROWS
- Check if column exists for one table in DB
- Where are WP_Errors Saved
- Get all images from this database table
- Error establishing database connection – high traffic?
- Switching database on the fly
- Allow logged in users to store and display some data
- Replace/Mute/Stop Search Query
- Populate dropdown from database
- How to merge two WordPress databases with the same structure?
- Finding the original login information in the database
- wordpress ‘database update required’ loop after update
- Database Table for customer user
- Is there a solution to auto-post data to a WP post from a database
- How to Access wp_usermeta Data Immediately After a New User is Created
- Cleanup: best way to remove WooCommerce comments from the wp_comments table
- How to prevent/delay MySQL connections when an object cache is used?
- How to paginate information obtained from a query to a custom table?
- How can I show related posts from multiple separate installations
- Uknown meta entries in wp_postmeta
- WordPress site URL changed; how to fix it without database access?
- Error establishing a database connection,
- Create table with dbDelta,can’t put any DEFAULT data
- Post Views / Hit Counter Problem?
- Trying to create a custom meta table for working with a custom table
- Connecting to a different database
- What is the purpose of the “term_id” column in the “wp_term_taxonomy” table?
- Debugging – logging database queries
- How to direct my site to the proper URL without Dashboard
- SELECT SQL_CALC_FOUND_ROWS with wordpress search
- Regenerate user_nicename column
- Create Pages for database content
- Should I use an additional column in the DB?
- Storing user submitted forms [closed]
- User Tracking for Custom Post Type “Lesson”. Database Queries and Performance
- How to add checkbox with multiple values in table?
- Re-creating a WordPress database
- Can’t log into wordpress site – I have made a new user and still cant access
- How to save EXIF metadata in WordPress database?
- Export WP Subsite DB Fully Ready for Import Elsewhere
- Sed Command Not Writing Changes to SQL file
- Realtime database update from 3rd party apps (notion, airtable, sheet, etc)
- Join Query on WP_USERMETA Table
- Recurring 502 Bad Gateway issue
- Error during installation (DB)
- WordPress Settings API Overrides My Previous Value
- Move Non-WordPress users table to WordPress database
- Is there an actual way to synchronize ‘production’ and ‘develop’ WordPress databases?
- Lost database connection
- is it possible to install new WordPress in an old WordPress folder?
- Can someoene please help with customization of a post?
- Insert JSON output into WordPress Database
- HELP $q=mysql_query($sel) or die(mysql_error()) HELP
- Updating Posts table in database without overwriting user generated content
- WordPress credentials not matched
- wp term relationships error
- 2 $wpdb queries causing error Table ‘wp_postmeta’ is specified twice, both as a target for ‘UPDATE’
- WordPress adding item to menu deletes post metadata
- Updating database with CSV file and Cron job
- Change Domain name in database
- WordPress character set issue
- Improving wpdb queries with large data
- Changed meta_key value in structures, now dashboard shows zero users
- Link wordpress with a SQl + MongoDB + .NET
- What am I doing wrong here? WordPress database error
- Why is wordpress trying to re-install itself?
- How to Determine a Post’s Last Edited Date?
- Category not displaying in add post, edit post, and categories page.
- Install WordPress with SQL database
- Creating Job Tickets
- $wpdb->prepare returns empty array
- Best db table structure for users with many records
- Prevent creation of unused database tables?
- How to store a plain password in WordPress database in another field
- How to stop WordPress from using utf8mb4_unicode_ci collation
- WP Multisite Users Not Linking