This should do the trick:
$sticky = get_option( 'sticky_posts' );
$args = array(
'posts_per_page' => -1,
'post__in' => $sticky,
'ignore_sticky_posts' => 1
);
$query = new WP_Query( $args );
$ids_by_category = array();
while ($query->have_posts()) {
$query->the_post();
$post_categories = wp_get_post_categories(get_the_ID());
foreach($post_categories as $c){
$cat = get_category($c);
$ids_by_category[$cat->slug][] = get_the_ID();
}
}
// sort by key
ksort($ids_by_category);
foreach ($ids_by_category as $category_slug => $ids) {
foreach ($ids as $id) {
printf(
'<a href="https://wordpress.stackexchange.com/questions/235659/%s">%d</a> %s<br>',
get_permalink($id),
$id,
$category_slug
);
}
}
Related Posts:
- How to get order of posts?
- Loop through all tags & output posts in alphabetical list
- Woocommerce custom loop to show all the products [closed]
- Sort by meta key on archive page
- Display three sequential posts on each page load, without repeating previous
- Sorting is not working in WordPress WP_Query
- Resetting post data to previous loop in nested loops
- Pagination returns 404 after page 20
- Make loop display posts by alphabetical order
- get custom post type by tag
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- Executing Queries in tag.php
- Group posts by custom field
- Trying to list out child pages with WP_Query
- Transient pagination not working properly
- get_posts() seemingly ignoring post_type
- How to show the posts of some category first, and then all other
- Why execute the_post()?
- Pagination stops at page 6
- Paginated HTML Sitemap
- Why does the_content not work like others for a set post id?
- How to limit total number of posts in wp query loop?
- How to change posts order on Category and Tag archives?
- Pagination is broken and I need help fixing it
- WP_Query on custom field and order results
- How to display 7 most recent days of posts?
- How to vary post loop results layout and resume?
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- Get a post from other loop each n-posts in the main loop
- Loop returning only 1 result
- WordPress Loop and $post
- Show post number in widget loop
- Excluding pages in WP_query using ACF
- reset to main loop doesnt work
- Some doubts about how the main query and the custom query works in this custom theme?
- Post loop for all taxonomy terms
- Stuck in the query loop
- Only display post if published in last 24 hours?
- Does wp track views for posts?
- How to remove the most recent post from $the_query
- WP_Query loop else statement not executing
- How do I rewrite this loop as a new WP_Query style-loop?
- Include current post into loop
- How to display the featured image for each post?
- Check for the main query from the template
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- has_excerpt() not working inside wp_query
- Meta query compare for ID’s greater than specific ID
- Save (and exclude) posts from loop to use in another loop on page
- Get all posts with empty meta_value
- Loop 3 posts column wise and continue the loop into same columns
- Check if a post has term inside loop
- Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?
- WP_Query with one category in args shows other categories
- Ordering posts by custom field and grouped by month
- relation OR instead of AND – Filtered term ID’s in loop
- Does query_posts have an effect on get_the_category?
- Second loop pagination changes URL, not content
- Compare “Main” post ID to ID inside wp_query loop
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Why does apply_filters behave different inside and outside a loop?
- Custom template for password protected page
- problem with the loop
- How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
- Function the_posts_pagination() not compatible with WP_Query arguments
- Prevent Duplicate Post Counted by Query
- Custom Woocommerce Product Query
- Show custom content when loop or wp query reaches specific time?
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- How to show specify category template for both parent and child category
- Pagination inside the blog page not working
- Woocommerce featured products query no longer working
- Custom Query Pagination not working on static front page
- sorting in wp query based on custom field value
- query all posts published by certain user id
- the_post_thumbnail and multiple WP_Query
- I have 3 categories, i want to display on a loop the last 3 of every category
- modifying the loop multiple times with arguments passed through ajax to wp_query
- WP_Query causing links to not work
- Retrieving category pages from subcategory returns empty sets
- WP_query for posts with same post type AND same post category
- How to solve this script problem in theme directory?
- Iterate through ID’s in loop
- Loop through multiple custom fields with increasing number
- Different number of posts showing in development vs production server
- An archive page without post format (just standard post)
- wp_query display posts based on day
- Sorting Posts Based On Meta Value Using AJAX
- Sorting: custom query with orderby meta_value_num THEN by title
- Converting an existing query_posts to WP_Query
- Pull Instagram images into an existing loop?
- Loop being strainge
- Multiple loop for “featured” items returns wrong posts
- Pagination in custom query not working [duplicate]
- Problem with WP_Query sort
- Get author meta data with no published posts in author.php?
- How to write a query-function as a query-shortcode?
- First post outside of loop, homepage only?
- Query All Posts: Either Display Most Recent or One with Particular ACF Value Chosen
- after refresh the id that shows correct in first time click, changes to 1