To get them broken down by Category, you need to loop through the list of categories and then query on each category:
$categories = get_categories( array ('orderby' => 'name', 'order' => 'asc' ) );
foreach ($categories as $category) {
echo "Category is: $category->name <br/>";
$catPosts = new WP_Query( array ( 'category_name' => $category->slug, 'orderby' => 'title' ) );
if ( $catPosts->have_posts() ) {
while ( $catPosts->have_posts() ) {
$catPosts->the_post();
echo "<a href="https://wordpress.stackexchange.com/questions/124037/the_permalink()">the_title()</a>";
}
echo "<p><a href="category/$category->slug">More in this category</a></p>";
} //end if
} //end foreach
wp_reset_postdata();
Related Posts:
- Query Set Order By Author
- How to orderby meta_value_num with dollar ($) sign
- WP_query sorting can’t sort danish letters (æ, ø, å)
- Sort WordPress Posts Meta value by Week not Day
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Ignoring ‘a’ when sorting posts
- order by numeric value for meta value
- Wp get all the sub pages of the parent using wp query
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- WP_Query for WooCommerce Products
- Get posts by meta data OR title
- Perform query with meta_value date
- WP_Query ordered by custom field that is a date string?
- Duplicate Queries
- Highlighting Sub topic in a post?
- How to count post type that has a particular term?
- how to retrieve specific product attribute value in an sql query?
- Foreach-generated custom tax queries, each with an ajax “Load more” button
- Sort by meta key on archive page
- WP_Query Performance Issues with meta_query
- WordPress custom archive page
- Retrieve or Query Pages by ID
- WordPress: Keep order of query_posts list of post ID’s using post__in
- How to make orderby ‘meta_value_num’ OPTIONAL?
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Meta query with order by another custom field
- How to do a query on custom taxonomies that is uncategorised?
- Empty tax_query array returns an empty array
- Meta Query for specific months
- How do I search inside specific taxonomies in WordPress
- How do I sort posts with multiple pages
- How to correctly pass values to wpdb->prepare()?
- Query: offset post list, unless it’s a specific category
- Setting get_queried_object
- WP_Query posts by distance based on LAT & LNG in Database
- remove query arg from url after set query
- difference between like ‘%%%var%%’ and ‘%var%’
- Changing WP_Query params with url Query Var
- only delete post within query / for each statement (front end)
- Sort query by author: 1 author, then others
- Custom Query num_rows returns wrong amount
- Overwrite YoastSEO meta-tags with another page’s [closed]
- How to orderby multiple meta fields if some fields are empty
- How to duplicate 5 posts out of WP_Query results?
- Slow queries on a huge database
- WP_Query with ‘rand’, but equal number of posts from the taxonomy terms given
- Multisite pagination issue by multi query archive 404
- Query with relation and one without relation using multiple taxonomies?
- Gallery shortcode numerical sorting
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- Transient api Caches confused
- How can I override one post and make it display content for another post?
- Get multiple users with meta value in one query and populate WP_User class
- How to order WP_Query to group results?
- Get a list of posts by specific category
- Shortcode for custom query not returning results when attributes are added
- Query where ANDing slug values not working
- How to filter query loop block with a search string from the query parameters
- How to use a dropdown to filter posts by custom field
- How to SQL query posts IDs by categories AND authors?
- Start Query from 2nd Post without offset
- orderby ignored by wp_query
- Post incorrectly excluded when using “category__in”?
- Query multiple post types, but different order for each
- Display posts ONLY from the current logged in user and current week/year/month Elementor posts
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Query against multiple locations within single custom post type post
- How to get_comments() ordered by date and parent?
- Sort posts on custom field AND after that sort on date?
- How to query users by post count no less than 10
- WP Query. Ordering posts by another post types meta
- How to make a search query if not found in post table then search in postmeta table?
- WP_Query about meta_key and its array value
- Create global array to compare inside a query
- Adding Category in WP_Query Not Working
- Merge two queries and remove duplicate
- how to show more than 1 post into three columns query
- Display three sequential posts on each page load, without repeating previous
- Using the same WP_Query for shop and widgets in WooCommerce shop
- How can I get all the posts that are related with a specific taxonomy term?
- Fetch only categorized posts
- Wrap group of wp query posts to parent div by date/year
- Custom pagination (Title, date and teaser)
- Pagination in custom query in a category page
- Get a list of the last posts grouped by author and filtered by category
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to query post ids liked by the Author
- Sort Posts with custom meta key by default which is currently set as optional
- Modify query after meta value
- Custom post types loop on a page template
- Showing posts from 4 categories along with all latest posts
- Pagination in WP query with transient API
- Parsing External Table Arguments
- difference between methods of query
- Query posts by meta value and sort by another meta key
- how to use transient method?
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- How to get posts that have certain meta key value and order based on another meta key’s value