简体   繁体   中英

Retrieve data from custom table

I am trying to use the following code to retrieve data from a custom table in WordPress:

$myrows = $wpdb->get_results( "SELECT id, name FROM mytable" );

The result set is empty, even though there is data in the table. Getting data from the database for the WordPress internal tables works without a problem.

For example, the following works without a problem:

$posts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type='post' ORDER BY comment_count DESC LIMIT 0,4");

Any thoughts on how to diagnose the issue?

If it's a problem with your SQL statement, an error will get echo ed out - where that goes in WordPress, I don't know.

WordPress does have a Error Logging widget you can install to help you debug your problem: http://wordpress.org/extend/plugins/error-log-monitor/

This should explain how to set up the logging so you can see where the problem is coming from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM