Exclude expired sticky posts

EDIT Here is another approach to the one in my ORIGINAL ANSWER. Instead of the need to alter the main query and $posts global to remove expired stickies, why not remove the posts entirely from being sticky, ie, unstick the posts which has expired. This way, we do not need to check for expired stickies … Read more

“Sticky” posts for each category (archive.php)

To make this more complete, here is what I have said in comments in reply to the question on hand Just to quickly explain, WP_Query fails catastrophically in some cases where empty arrays are passed to some of its parameters, instead of also returning an empty array as we should expect, WP_Query returns all posts. As for getting the correct stickies, … Read more

Get sticky post from category?

Use the below code in the mainpage template to show the sticky posts. <?php $args = array( ‘cat’ => 42, ‘posts_per_page’ => 10, ‘post__in’ => get_option( ‘sticky_posts’ ), ); // The Query $the_query = new WP_Query( $args ); // The Loop while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; } The … Read more

Randomly placed sticky custom posts complemented by blog posts

This did it: $products = get_posts(array(‘post_type’ => ‘products’)); $numbers = range(0, 8); shuffle($numbers); $x = 0; foreach($products as $post) : setup_postdata($post); $product = new WP_Query(array(‘p’=>$post->ID,’post_type’=>’products’)); if (!empty($product->posts)) array_splice($posts,$numbers[$x],0,$product->posts); $x++; endforeach; foreach($posts as $post) : setup_postdata($post); …

All sticky posts are returned in custom query

This is default behavior when the post__in parameter is used. If you read the docs, you will see that you should set ‘ignore_sticky_posts’ => 1 to eliminate sticky posts being queried EDIT Your query arguments should look like this $recommended_args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3, ‘post__in’ => get_option(‘sticky_posts’), ‘orderby’ => ‘date’, ‘ignore_sticky_posts’ … Read more

How to make all posts in a category sticky?

You rather need a save_post hook. Check following code it marks the post sticky for the specified if it is not already. add_action( ‘save_post’, ‘mark_post_sticky’ ); function mark_post_sticky( $post_id ) { if ( !wp_is_post_revision( $post_id ) && !isset($_POST[‘sticky’]) && in_category(‘bestcategoryever’,$post_id) ) { $_POST[‘sticky’] = ‘sticky’; } }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)