Result Types of $wpdb->get_results()
If you query the WordPress database using $wpdb->get_results(), you can specify the desired return type. You can select between four options.
OBJECT
This one is the default. You get an array of objects of type stdClass. The array uses a numeric identifiert, that starts with 0. First object is $result[0], second object is $result[1] and so on.
OBJECT_K
OBJECT_K is pretty similar to OBJECT, the difference is, that the array key matches the primary ID of the desired object. So, if your result has the ID 15, you can access it by $result[15].
ARRAY_A
You receive an array with the database column names as key.
ARRAY_N
You get an array with incrementing IDs as key.
Related Posts
- Query Custom Data in WordPress
- Debug WordPress SQL Queries
- Manage MySQL Databases and Users from the Command Line
- Get ID of Data Inserted by $wpdb->insert
- Configure WordPress Backend Search to Search Titles Only
- Force Easy Digital Downloads Updater to Check for Updates
- Tutorial: Ubuntu 18.04 LAMP Setup for WordPress
- Get Post Meta