• If I run a query with some args and get a list of posts, how can I organize the posts separated by category and display the title of each category?

Viewing 1 replies (of 1 total)
  • You could loop through the categories with a foreach and run the query each time. Pseudo code:

    $categories = get_categories();
    foreach ( $categories as $category ) {
      echo "<h1>{$category->name}</h1>";
      $args = array( 'category_name' => $category->slug );
      /* WP_Query loop here using $args */
    }
Viewing 1 replies (of 1 total)
  • The topic ‘How to organize a WP_Query's list of posts by category and display category titl’ is closed to new replies.