Show all sticky posts, WITH pagination

Based on this post, i did this test and go it working: $sticky = get_option( ‘sticky_posts’ ); $ppp = get_option(‘posts_per_page’); if (!is_paged()) { $custom_offset = 0; } else { $custom_offset = $ppp*($paged-1); } $args = array( ‘numberposts’ => $ppp, ‘offset’ => $custom_offset, ‘post__in’ => $sticky ); $posts_data = get_posts( $args ); $pd = count( $posts_data … Read more

Set sticky posts schedule (Automatic)

OK I got it working this is the code I used, I am not sure if it is the best practice but it certainly works. In functions.php where I make the posts sticky from the front-end I added this to update the post_date to today so I can have control over the sticky period: $newdate … Read more

Exclude sticky post from main query?

query_posts isn’t recommended because its breaks things. You’re really close, but just declaring the function itself will not work. You need to hook the function into something. In your case, this would be pre_get_posts. Example (with “namespaced” function): <?php // this is key! add_action(‘pre_get_posts’, ‘wpse74620_ignore_sticky’); // the function that does the work function wpse74620_ignore_sticky($query) { … Read more

Query *only* sticky posts

I currently have no posts set as stickies on the website. Which tells me that nothing should show up in the loop. Exactly where you are wrong when passing an empty array to post__in. WordPress has some silly bugs which has no proper workaround and will most probably stay active bugs for a very long … Read more

WP_Query: Why is sticky post not first item in loop?

If you look ate the source code where stickies are included, we find the following condition before WP_Query carries on to include sticky posts if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q[‘ignore_sticky_posts’] ) { The big game player is the is_home condition. Conditionals inside WP_Query is set according to the … Read more

why ignore_sticky_posts in sticky post query

We all know that ignore_sticky_posts is used to exclude sticky post from your custom query. – No, this assumption is wrong. What ignore_sticky_posts means: Even though in natural English, ignore_sticky_posts sounds like WordPress should ignore all sticky posts from the query, in reality that is not what WordPress does. Instead, you should read ‘ignore_sticky_posts’ => … Read more

Sticky Posts exceed posts per page limit

Here is an approach to account for sticky posts by getting the number of sticky posts (if any) and include that in the calculation posts_per_page parameter: add_action(‘pre_get_posts’, ‘ad_custom_query’); function ad_custom_query($query) { if ($query->is_main_query() && is_home()) { // set the number of posts per page $posts_per_page = 12; // get sticky posts array $sticky_posts = get_option( … Read more