Regarding wordpress.org - sticky posts are displayed at the top but they also appear again in the loop.
For the main loop on my homepage I want to display the sticky posts at the top BUT I don't want the post to appear again in the loop, otherwise it appears redundant to the visitor.
Problem with the below code is they remove the sticky post from the top.
I want to KEEP the sticky posts at the top
but REMOVE/EXCLUDE it from the loop. Is this possible?
CODE A: This removes sticky post from top
function mango($query){
if ( $query->is_home() && $query->is_main_query() && !is_admin() ) {
$query->set( 'ignore_sticky_posts', true );
}
}
add_action( 'pre_get_posts', 'mango' );
CODE B: This removes sticky post from both the top AND loop
function mango($query){
if ( $query->is_home() && $query->is_main_query() && !is_admin() ) {
$query->set( 'post__not_in', get_option( 'sticky_posts' ) );
}
}
add_action( 'pre_get_posts', 'mango' );