Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this code to display only the latest sticky post on the front page.

the strange thing is that, when I'm logged-in it shows non-sticky latest post, even if it's private...

<?php get_header(); ?>
<?php if ( is_home() && !is_paged() ) : ?>

<?php
    // Get IDs of sticky posts
    $sticky = get_option( 'sticky_posts' );
    // first loop to display only my single, 
    // MOST RECENT sticky post
    $most_recent_sticky_post = new WP_Query( array( 
    // Only sticky posts
    'post__in'            => $sticky, 
    // Treat them as sticky posts
    'ignore_sticky_posts' => 1, 
    // Order by date to get the most recently published sticky post
    'orderby'             => date, 
    // Get only the one most recent
    'posts_per_page'      => 1
    ) );
?>

<?php while ( $most_recent_sticky_post->have_posts() ) :  $most_recent_sticky_post->the_post(); ?>
<!-- your code to display most recent sticky -->

<?php endwhile; wp_reset_query(); ?>
<?php endif; ?>

The idea is that those logged-in see the exact same thing as those not logged-in.

Does anyone know how to present that?

share|improve this question
add comment

1 Answer 1

If you want both logged in and non-logged in user to see the same thing then you only want 'published' post status, at least it doesn't make sense to me to show 'private' posts to non-logged in users. Alter you query to include that condition.

$most_recent_sticky_post = new WP_Query( 
  array( 
    'post_status' => array( 'publish' ),
    // Only sticky posts
    'post__in'            => $sticky, 
    // Treat them as sticky posts
    'ignore_sticky_posts' => 1, 
    // Order by date to get the most recently published sticky post
    'orderby'             => date, 
    // Get only the one most recent
    'posts_per_page'      => 1
    ) 
);

ignore_sticky_posts, when true as you have it, treats sticky posts like ordinary posts, which is not what your code comment says but I think that is what you mean.

share|improve this answer
    
Hmmm, that actually didn't work: I get http Error 500. So "'ignore_sticky_posts' => 1," means true? –  Django Feb 17 '13 at 4:30
    
Try again. There was a syntax error. Yes, 1 will evaluate to true. –  s_ha_dum Feb 17 '13 at 5:09
    
that worked marvelously, thank you sir –  Django Feb 17 '13 at 5:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.