Add this after $args
$categories = get_terms('category', $args); //get all categories
$count = count($categories ); //count categories
if ( $count > 0 ){ //Check if you got some categories
foreach ( $categories as $category ) {
$args['cat'] = $category->term_id; //get the id of each category and add it as a parameter
$loop_our_work = new WP_Query( $args ); //start a new query with 'cat' parameter inside of it for each category
if($loop_our_work ->have_posts()) { //always check if query have posts
//echo here category name or whatever you need about category
while( $loop_our_work ->have_posts() ) : $loop_our_work ->the_post();
//echo here whatever you need for each post on current category inside the loop
endwhile;
} //endif
The code is not tested but i hope it helps you
Related Posts:
- List events by month
- Custom post type loops with different page templates
- How do you output custom code between posts in the loop?
- How to append element after thumbnail
- Display custom field of specific post where post title matches variable
- Create a random unique 6 digit number as custom field for custom post type
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Very Slow Page – How to Optimize # of Queries?
- Custom Post Type Loop throws 500 error when used in widget
- How to make sure content doesn’t display if selection is empty
- CPT + CMB2: data not displaying for only first post in loop
- How do i calculate the total of values of custom fields in custom post types?
- I would like to have different styles for my posts based on the content of each post
- Checking if Post Title is Unique as Loop Criteria
- Custom Tag Description unable to display just below and outside of the Loop
- Including all post id’s of a custom post type into an array
- How can I group posts by months and years?
- Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- Loop increase number
- Using wp_query to modify the loop in index.php for a CPT
- Control content before and after custom post type loop
- Get data from PHP to JavaScript to set position of each post on front page
- foreach loop inside the loop creating duplicates in output
- Compare Two Custom Post Types Using The Same Custom Taxonomy
- How can I increase the post count for custom post types only?
- Show the categories the current post has
- Fetch data from two custom post types and create multidimensional array for output to html table
- Page that lists publications by classifying them by taxonomy
- CPT loop doesn’t seem to account for post date?
- Pagination not working in custom post type. Help
- when looping through custom post data not appearing
- Accessing download link from the loop with WP Download Manager Pro
- Custom Post Type has wrong label and is not found when called by a loop
- Combine multiple separate lists into one
- Show parent category and subcategory once in while loop
- WordPress trying to query two custom types to get child from the parent
- Add active class to foundation 6 tabs while looping categories
- Display related post content and custom field content
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Strange behavior on WP_query
- get_post_meta for Custom Post Type ( CPT )
- WordPress query posts by custom post type not workng
- WordPress Custom Post Type and sort by Tags
- Posts without featured image using other post’s featured image
- Order by custom field attribute
- Looping taxonomy in taxonomy?
- Query Custom Post Type by Tag
- How do I filter a custom post type loop by a field?
- GravityForm: Populate Dropdown with custom post type [closed]
- Loop of custom post type names
- Return array of categories to php function for current post
- Link users to a custom post type
- How to get all posts except for one post from a certain custom post type?
- How to output wordpress custom tags separated by comma?
- Creating Accordians in WordPress Theme
- Remove duplicated values from a loop
- Loading all files within a directory
- Blog page showing same content as homepage
- Using pre_get_posts to filter one loop in a multiloop archive
- Custom Post Type Loop within Shortcode
- How to insert content from another Custom Post type into Post?
- Filter post by current 2 differents users id
- Using several custom fields as custom post title
- Custom Post Type without an archive page
- Get rewrite slug of custom post type in template
- Show Different Header on a Specific Post ID
- Get Post Primary Category
- Weird problem happening with custom taxonmy when creating/updating posts
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- Admin notice not displaying
- Can’t get order_by meta_value_num to work properly
- Display different content on homepage depending on post type
- Create custom post type on successful woocommerce order [closed]
- get_template_part for each level of taxonomy term
- WP_Query | ‘post_type’ doesn’t work
- How to call custom single post?
- How to connect two custom post types with nested loops
- Pass the_post() as a parameter
- Filter by custom taxonomy slug on a custom post type
- Adding custom tables to WordPress
- Query custom post type in the loop
- Creating Multiple Loops in Genesis, One Post then 20, each with custom fields
- Normal pages as children of my Custom Post Type
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Loop through Custom Post Type, and then show children within each iteration
- Only show posts from a certain category?
- Change or update WordPress loop based on dropdown selection
- Dynamic page outside WordPress
- get_template_part and template file names
- Can I create a loop with multiple post types and specify different $args for each post type?
- Using wordpress template tags within an array
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Getting the URL of the parent page
- Custom query to filter posts that have current post as a taxonomy [closed]
- Custom post type permalink returns bad url
- Return the thumbnail meta data for getter and setter
- Display CPT posts based on specific taxonomy
- How to display selected taxonomies by their parent
- Creating select dropdown with parent-level custom post types