The issue is that you are using the function query_posts
this only queries the default result on that page. It’s advised that you use wp_query
instead, it just eliminates the margin for error or unexpected results.
You can create a new query like below, and specify explicitly how many posts to return:
<?php
$sticky = get_option( 'sticky_posts' );
rsort( $sticky );
$args = array(
'post__in' => $sticky,
'posts_per_page' => 10
);
$sticky_query = new WP_Query( $args );
while ( $sticky_query->have_posts() ) : $sticky_query->the_post();
// Do stuff with sticky posts
endwhile;
wp_reset_postdata();
This method also allows you to drop the array_slice
process. So you can simply change posts_per_page to a number of your choice
Related Posts:
- Apply styling only to first page sticky posts
- How to retrieve “sticky” post outside the “loop”?
- 3 Posts in Loop, Show Stickies First
- Move sticky posts down in main loop
- sticky post in custom loop
- Blog page Server error 500 with stick post loop in query.php
- Showing sticky posts with get_posts()
- Exclude duplicated $sticky post from combined loop content
- Exclude first post (sticky or not) from the loop using query_posts()
- Custom Query with Sticky Posts
- Insert/sticky multiple posts in multiple positions
- Different style for first two (sticky) posts
- I make sticky post for my archive page for custom post type with ACF field and loop is not working
- How to fix pagination for custom loops?
- Why should I put if(have_posts()), is while(have_posts()) not enough?
- AJAX with loop filtering categories
- Remove the Homepage Query
- A search for ‘0’ returns results
- Custom Loop and Infinite Scroll
- Loop that displays PARENT PAGE & CHILD PAGE & outputs GRANDCHILD PAGE title and content
- wp-admin redirecting to https, denying login
- Add Incrementing ID to each paragraph in the_content
- Multiple posts with one loop iteration
- Query date in wordpress loop
- Custom Loop, Match Category with Page
- get_the_content not working in loop?
- Get link of inserted media file of post within loop
- If No Search Results, Show Posts from Alternate Search Query
- Output shows a page instead of a list of blog postings
- How to add “time” data this?
- multiple loops with pagination on the same page
- Custom search form to display users only
- Multiple loops on the same page removing post tags
- Pages inside a page (with thumbnails)
- How to make post content from each post display within the same div
- How to order posts by meta_value created inside loop?
- WordPress Redirects on Install
- Problems with loop
- Repeating Loop on my Posts Page
- Combining action and filter?
- Calling & display certain product category loop and pagination on the homepage
- Display Authors in a grid loop
- Infinite Scroll and DFP
- Blog’s post count cause irratic behavior
- show random image in loop if image is not set
- Get Page content to displayin Bootstrap Modal
- Pagination – works on local but not live dev!
- Does WordPress Loop have a function like Shopify’s cycle?
- How to show more random posts if Tag has less than 3 posts
- How to add a specific div element to the first post in a row?
- While loop with bootstrap [closed]
- Need to add class to first element in a foreach loop
- Scrolling Posts with Ajax
- Sort posts by first letter in the title, not by first number
- how to replace get_template_part(‘loop’,’tag’) with explicit styled version?
- What PHP Needed to Make One Loop with Multiple Styling?
- Simple foreach loop help needed in wordpress “the loop”
- How to create custom popup in shop page on every loop products?
- Loop through an array inside a class using foreach [closed]
- using wp_get_attachment_image_src in foreach loop
- Grabbed Post ID under WP loop, but still couldn’t Print Post title
- How to separate posts loop in to two columns? [duplicate]
- query_posts clarification needed
- Blank content php code not parsing advanced custom fields gallery add-on [closed]
- Three Column Loop
- Split loop into columns
- get_posts() forcing ignore sticky posts on main loop
- display post tags on single.php inside loop
- make diffrent template on last six post published
- “the_excerpt” in loop just keeps repeating first post?
- wpdb inside foreach loop only returns first result – 2 other similar cases found [closed]
- Using jQuery .after inside loop
- How to check all items in a loop have post thumbnail?
- Page Navigation Outside the Loop
- How to make the following loop break/stop when it reaches 2 posts (custom post types called Topics)?
- How to loop specific Category menu from archive page?
- How to display post tag on each post? [closed]
- How can I pass additional params to a shortcode while in a loop?
- Solved – Inserting content inside the WordPress loop
- Add Search and Filter functionality to custom loop
- How to add “NEW” badge on latest posts or published 3 days interval
- Add all category as classes in foreach loop
- Exclude posts from loop by term
- How to avoid appending “null” in Ajax?
- Alternative layout the loop
- Why loop renders only last metabox from array? [closed]
- Structure and Display Content from Multiple Pages on Single Page
- Creating a archive for taxonomy terms, not the term results
- Thumbnail of the latest posts page
- Display latest posts using WP Loop with different size divs
- Combining external feed into post loop
- Code to check amount of blog posts and add css
- Loop to get current parent page “content” and his children content
- Add Div IDs dynamically to CSS
- Load featured article once in a loop
- Please help me to win the battle with 2 column loop by category
- Display content from “About Us” page on the Home Page
- repeating posts on 2nd page to posts
- Limitless amount of posts in custom archive page
- Two loops in CPT archive page, exclude posts from main query