How to get all wp_posts in wordpress fetched from database

I have downloaded a theme and installed it. Here the theme has custom fields for limited numbers. For ex. author_name, comments but, I want all the wp_posts to be displayed.

And prior to that, actually I have a database associated with this. So basically I want my piece of code to read the whole database and represent it in columns in my wordpress page. For ex. author_name, ping_status, post_status etc.

So basically I want to write a function, that can access my database and pull the data from database and dump back in my wordpress page.

I don't know if I put it in the right words, but please do help me get through this.

Topic list custom-field Wordpress

Category Web


You can interact with the WordPress database with the help of the wpdb class:

https://codex.wordpress.org/Class_Reference/wpdb

For example, the next code will get you all the rows from the wp_posts table as objects:

global $wpdb; $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE 1", OBJECT );


More explain your question. if you want to fetch all post in database you this code

$query = array(
'post_type' => 'my-post-type',
'post_author' => $current_user->ID,
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 
'future', 'private', 'inherit', 'trash') );
$loop = new WP_Query($query);
while ( $loop->have_posts() ) : $loop->the_post();

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.