Answer the question
In order to leave comments, you need to log in
How to get all posts with their category names?
you need to supplement the query in such a way that would get all the posts with the names of their categories
$wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY `id` ASC" );
Answer the question
In order to leave comments, you need to log in
$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>";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question