$wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY `id` ASC" );
$query = new WP_Query( array( 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'ID', 'post_status' => 'publish', ) );
while ( $query->have_posts() ) {
$query->the_post();
the_title(); // выведем заголовок поста
foreach( get_the_category() as $category ){
echo $category->cat_name ;
}
echo "<br>";
}