admin管理员组

文章数量:1322172

I'm trying to exclude 3 Sticky posts from my blogs loop, I tried some snippets of code, but with no success. I could use some help.

<?php if ( $posts->have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( $posts->have_posts() ) : $posts->the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<div class="clearfix"></div>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
<div class="clearfix"></div>
<?php $wp_query = new WP_Query($args); global  $wp_query; if ($wp_query->max_num_pages != 1) { ?>

I'm trying to exclude 3 Sticky posts from my blogs loop, I tried some snippets of code, but with no success. I could use some help.

<?php if ( $posts->have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( $posts->have_posts() ) : $posts->the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<div class="clearfix"></div>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
<div class="clearfix"></div>
<?php $wp_query = new WP_Query($args); global  $wp_query; if ($wp_query->max_num_pages != 1) { ?>
Share Improve this question edited Sep 16, 2020 at 7:57 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Sep 16, 2020 at 6:03 Ioannis PolitidisIoannis Politidis 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

If you want to exclude sticky posts then you can use it.

<?php
$args = array(
    'posts_per_page' => 10,
    'ignore_sticky_posts' => 1
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
?>

For More details:

https://www.wpbeginner/wp-themes/how-to-exclude-sticky-posts-from-the-loop-in-wordpress/

本文标签: Exclude Sticky Posts as everyone