Quantcast
Viewing all articles
Browse latest Browse all 10

WordPress Get DB Table Column Names

Image may be NSFW.
Clik here to view.
wordpress-db-header

To get the column names for a MySQL database table in WordPress, use the following:

global $wpdb;

$table_name = $wpdb->prefix . 'posts';
foreach ( $wpdb->get_col( "DESC " . $table_name, 0 ) as $column_name ) {
  error_log( $column_name );
}

Which will result in something like the following being printed to your debug.log:

ID
post_author
post_date
post_date_gmt
post_content
...

You get the idea

The post WordPress Get DB Table Column Names appeared first on Fox Run Software.


Viewing all articles
Browse latest Browse all 10

Trending Articles