Using categories & “stickyness” together

Just add ‘post__in’ => get_option(‘sticky_posts’) to your query, to confine your query to only sticky posts. So, $getHighlights = array( ‘numberposts’ => 7, ‘post_type’ => array(‘post’,’Event’), ‘post__in’ => get_option(‘sticky_posts’), ‘category_name’ => ‘Highlights’ ); should work for you. Edit: This is how you can merge two arrays to get the sticky posts at the top of … Read more

How do I show sticky posts on a static front page that also contains content?

Something like this should work: $sticky = get_option( ‘sticky_posts’ ); if ( !empty( $sticky ) ) { // don’t show anything if there are no sticky posts $args = array( ‘posts_per_page’ => -1, // show all sticky posts ‘post__in’ => $sticky, ‘ignore_sticky_posts’ => 1 ); $query = new WP_Query( $args ); if ( $query->have_posts() ) … Read more

Limiting query_posts to 1, regardless of sticky post?

$GLOBALS[‘wp_query’]->found_posts will give you the number of posts. $GLOBALS[‘wp_query’]->posts is an array with all the posts found. So instead of while ( have_posts() ) : the_post(); use: setup_postdata( $GLOBALS[‘wp_query’]->posts[0] ); get_template_part( ‘content’, ‘super’ ); This way you don’t run through all post, you really just use one. And please read When should you use WP_Query … Read more

Highlight a Featured Post?

Use the “sticky” feature. In the “Page Attributes” metabox (labelled as Publish), if you click the “edit” link next to the Visibility option, there is a checkbox which allows you to “Stick this post to the front page”. Unless a theme overrides the default query, that post will show up above all the others. In … Read more

Ensuring sticky posts are retrieved first (without using two queries)?

Digging through the source code I couldn’t really find any weird logic that would cause ‘category__in’ to break the ordering of the results. If you do, you might as well file a bug in the WordPress Trac. It’s also hard to reproduce this sort of issue, because it might depend on another issue which is … Read more