Don’t use $wpdb->prepare with table names. prepare will quote your table names that will result in incorrect SQL.
It is unnecessary overhead as well. Your table name should never, and in your case isn’t, be user-supplied data. You have no need to escape it. ‘prepare’ is for use on user-supplied data, such as data from a form or a $_GET parameter.
You have no user-supplied data so all you need is
$wpdb->get_results("SELECT * FROM {$tablename}");
Related Posts:
- Retrieving custom fields with $wpdb->get_results
- SQL query for custom taxonomy slugs
- How to optimize multiple insert into wordpress database
- How to store sensitive user data (passwords)
- I can’t write in my DB using $wpdb->insert
- Should I use wpdb prepare?
- Is it mandatory to use $wpdb->prefix in custom tables
- $wpdb->insert_id
- Check for success of $wpdb->update() correctly
- Getting wrong relationship value in $args in wp_Query?
- WordPress and multithreading
- $wpdb->insert is changing a value
- Actions or filters fired when data is saved in a custom table
- Display only certain posts based on visitor’s country?
- Custom Plugin Database relations
- why creating tables using $wpdb is not being executed while installing plugins?
- How to use mysql IN statement with wpdb update method?
- How to add SQL file with PHP to WordPress database [closed]
- Using $wpdb object in a widget
- Activation hook not creating table
- $wpdb -> Batch insert from XML File?
- How to Download and install plugin database remotely
- How to insert data to a database table when the field is not yet created?
- Where to store the name of a custom table?
- include wp-blog-header not working on MAMP
- creating custom function to log actions in plugin
- Issue regarding $wpdb->prepare()
- Error on inserting a form value to database
- How to create database table, add data, update and delete using wpdb via plugins?
- Using WPDB to output raw XML fails because of wp-blog-header.php
- how to search users by ajax live search
- Adding custom end points, No error line
- Intermittent database errors when accessing WordPress database
- Storing data in wordpress database from ajax call from different website
- wpdb->prepare and mysql UPDATE – how is it done?
- $wpdb->prepare with LIKE and sprintf
- $wpdb->update() always need a second try
- Using AND and bracket grouping in SQL not working
- Data inserted by wpdb insert is different than data pressnt in database.
- Proper Prepare Statement for ALTER TABLE and using AFTER
- wpdb->get_var always returning 0
- $wpdb->prepare is not working like mysql_real_escape_string
- How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?
- $wpdb in php 5.5
- Plugin to create Posts and Forums then choose category and parent forum
- $wpdb->update Issue
- How to relate the Category to user?
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- Why doesn’t my Table get created?
- How to display specific data from a custom table to logged in users with a custom role
- $wpbd->insert_id is returning null
- How to get inserted row IDs for bulk/batch insert with wpdb query?
- WordPress Query doesn’t return the correct value
- User avatar-ACF fields
- bindParam? WordPress 4.9.5 SQL LIKE statement %s and %LIKE%
- Update database record in plugin
- Organising and completing posts (mark as read and hide)
- Dedicated server and WPDB Class : huge slow-down of the website
- How to implement pagination into a wpdb->result query?
- How to CRUD from wordpress database in wordpress theme?
- $wpdb how can i save my postmeta table before querying it
- How to add chunk of php, html, and sql code to variable an append to $content
- WordPress plugin tables become corrupt
- Nothing happens on WordPress Update command
- Fixing plugin for wpdb::prepare
- Get all the related data from WordPress DB
- select rows based on exact time (hours, minutes and seconds)
- multiple record insert creating many duplicate records
- Is there any plugin development framework
- How do I add CSS options to my plugin without using inline styles?
- Handling results from data hooked into admin_post
- Get list of available wordpress actions
- How can i list current author’s categories?
- Handling form request from plugin file
- Finding the paragraphs in content
- A better way to include localized labels in WordPress plugins
- Clearing caches on plugin uninstall
- plugin settings – uploading multiple files with a single button
- Getting term_id for newly created or edited term
- How to insert text at the current cursor position in Gutenberg?
- How to fix this URL error in WordPress ” data-wplink-url-error=”true”>
- Edit Images From the Front End without Access to WP Admin
- How to remove or add submenu item on plugin activate or deactive
- jQuery in WordPress Plugin
- Why is my plugin version 0.1?
- WP Plugin Running before jQuery
- How to include jQuery into my plugin so I can use it on plugin page?
- WordPress multisite,use same cookies across all website?
- How to save post meta as an array in Gutenberg?
- Duplicate shipping method logic to another shipping method [closed]
- REST Endpoint API 404
- How to disable a jQuery plugin on WordPress plugin page
- jQuery UI tab does not work in the plugin page
- Using HTML links within translatable string
- Adding an external stylesheet to a plugin
- How to write a custom shortcode name book?
- get the term_id of current taxonomy page
- Custom query not working in plugin admin page
- Developing Themes on WordPress, Looking for Excellent Tutorials [closed]
- User set default settings for a Block in Site Editor