How do we get sticky posts to “stick” to category pages? The answer to this question turned out to be much more involved than I had imaged. After scouring the internet/codex I managed to found this solution.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* stickies to top for news category (34) */ function jma_child_sticky_posts_to_top($posts, $q) { //check to see if it's the news cat //for specific cat $query_vars['cat'] !== 34 //for all cat use (!isset($query_vars['cat'])) $query_vars = $q->query_vars; if (!isset($query_vars['cat'])) { return $posts; } $stickies = array(); foreach ($posts as $i => $post) { if (is_sticky($post->ID)) { $stickies[] = $post; unset($posts[$i]); } } return array_merge($stickies, $posts); } add_filter('the_posts', 'jma_child_sticky_posts_to_top', 10, 2); |