Query WordPress Database and Post HTML Table

I’m looking for some help building the base code to query my WP database, retrieve a table and then post this on a page. There seems to be a lot on the web to assist with this, however with limited php/sql coding background I’m finding it hard to wade through everything. I find things easier to learn by reverse engineering and building from there.

I’ve downloaded the plugin PHP code snippets (Insert PHP) which gives me the ability to add php code into posts (being deprecated in next version) or shortcodes.

I believe the following code should be sufficient to query the wp_post table and return the table data in an array.

global $wpdb;
$result = $wpdb->get_results(‘SELECT * FROM ‘ . $wpdb->posts . ‘ LIMIT 10’);

What I want to be able to do from here is generate a html table in a WP page using this data. How would I go about this?

Once I’ve got this base code sorted I can build off this and develop what I need.

Any help is greatly appreciated.

Read more here:: Query WordPress Database and Post HTML Table

Leave a Reply

Your email address will not be published. Required fields are marked *