A
A
alexanderqwert2018-06-03 15:02:17
WordPress
alexanderqwert, 2018-06-03 15:02:17

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

1 answer(s)
S
Syomka Gavrilenko, 2018-06-03
@cema93

$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 question

Ask a Question

731 491 924 answers to any question