Skip to main content
syntax error
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

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.

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.

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.

Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

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.