You have 2 two problems here:
– You can’t use $wpdb-> with custom tables because [postmeta, posts, …] are variables in the class $wpdb.
– WHERE ‘id’= 2 is not correct WHERE id = 2
So it should work:
global $wpdb;
$table_name = "_customtable";
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name WHERE id = 2" );
foreach ($retrieve_data as $retrieved_data) {
echo $retrieved_data->item_value; }
Regards.
Related Posts:
- Advanced SELECT query with condtional statements
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- WordPress Database Query works in phpMyAdmin but not in the code
- Using wpdb to connect to a separate database
- get_results using wpdb
- How to fetch Data in WordPress using MySQLi or $wpdb
- wpdb->insert multiple record at once
- How to define composite keys with dbDelta()
- Export wordpress table to excel
- Inserting Post Meta From SQL
- Why does dbDelta() not catch MysqlErrors?
- What causes the “max_user_connections” warning on WordPress frontend?
- Change all http to https in mysql databse?
- WooCommerce – Query for ordered products
- How to execute mulitple statement SQL queries using $wpdb->query?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Database slowdown after update to 3.4.1
- Query WordPress database by registered date and role
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- Select Multiple meta_value from WP DB; Single Query
- wpdb_prepare with multiple or condition
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- CRUD operations using WordPress database API
- Select two sums with single get_var statement
- Redirecting to old domain after migration website
- Slow queries constantly getting stuck on WordPress database of ~100,000 posts
- Create table from array with prepare
- How Can I Put Meta_Compare in the Database-Query?
- WordPress running SQL query to update database from form
- Query multiple tables at once?
- Have working sql query… trying to adjust it to use $wpdb
- $wpdb->query can’t insert data
- Trouble running $wpdb->query() with last_insert_id
- Connecting to a different database
- SQL query to set posts in bulk based on the post content
- How to create more than one new wpdb object?
- How to connect and insert data in database of wordpress?
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- How to insert a value to decimal type field using wpdb->prepare?
- Insert NULL value using prepare()
- “BS_” rows in postmeta table
- Where is the HTML-handler part in the wpdb class?
- insert data from a form:: Warning Empty query mysqli::query()
- How can I get $wpdb to show MySQL warnings?
- How To connect to the same WordPress database with different database user
- Should I Use only wpdb Class to Write Custom Queries?
- using same mysql user with many databases
- Pulling values from a sepcific row in table
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- Uploading to WordPress Database
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- MySQL SELECT increment counter
- Detecting errors generated by $wpdb->get_results()
- wpdb update add current timestamp not working
- Restoring WordPress posts from database only
- Slow wp_term_relationships query
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
- What are conventions about the schema of the $table_prefix
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- Is deleting orphaned wp_options entries safe?
- How to solve slow WordPress site caused by attachment_metadata
- Delete all post meta except featured image
- Large database causes slow load
- Safe way to find last inserted id in a table?
- How to insert data into MySQL database from the form created in WordPress site
- Multiple postmeta with same name for one post in wp_postmeta table
- Which is more efficient? Using usermeta, or creating a new MySQL table?
- Modify Database in Multi-Site wp_usermeta table
- Hook directly into query execution
- Create WP_Query to search for posts by their categories or their parent/child categories
- $wpdb doesn’t like to store arrays
- Handling large N data in WordPress
- How to Mirror WordPress database from Remote server to Local server
- Update results, Before deleting the related category [closed]
- A MySQL DB within a MySQL DB
- Is there a way to recover the table wp_term_relationships?
- Trouble Migrating all data blog from WordPress.com to WordPress.org
- Historic WordPress database connection
- Check if an option exists and get its value in one hit
- $wpdb error (Call to a member function insert() on a non-object)
- Is it important to have integers inserted using %d rather than %s?
- I can’t update my data through $wpdb
- Optimizing function that automatically creates internal links based on post title string
- How to get product order by two custom taxonomy in wordpress
- Updating with $qpdb->query() always returns 0 rows affected
- Get results from wordpress data custom table
- Outputting query results
- Add row to custom database Table and delete all rows older than 1 day
- How to display data from db in select list [closed]
- Creating and Using Tables in the WordPress Database
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- SELECT rows between two datetimes when the range is dynamic [closed]
- Correct and secure way to access a custom SQL database in a custom PHP template file
- How to optimise this database query?
- Missing latest posts and options after DB migration via phpMyAdmin
- How do i get value from wp_postmeta?
- “MySQL server has gone away” since update to 3.8
- featured image not showing up with mysql_connect