首页 > 解决方案 > 每页帖子不限制查询中的帖子

问题描述

我有一个查询吐出没有特色的帖子,但由于某种原因posts_per_page限制器不起作用......

<?php $featured_posts = get_posts( [
        'posts_per_page' => 3,
        'orderby' => 'date', 
        'order' => 'DESC', 
        'update_post_term_cache' => false, 
        'update_post_meta_cache' => false, 
        'meta_key'   => '_is_ns_featured_post',
        'meta_value' => 'yes',
        'fields'     => 'ids',
            ] );

        query_posts( array( 'post__not_in' => $featured_posts ) );

        while ( have_posts() ) : the_post();?>
            <div class="news-item-block col-md-4" role="article">
                <a class="news-item-image-link" href="<?php the_permalink(); ?>">
                    <?php the_post_thumbnail('news-grid-image'); ?>
                </a>
                <span class="news-item-date"><?php the_date( 'M d, Y' ); ?></span>
                <a class="news-item-title" href="<?php the_permalink(); ?>">
                    <h1><?php the_title(); ?></h1>
                </a>
            </div>
        <?php endwhile;
        wp_reset_query();
    ?>

感谢您对此问题的任何见解。

标签: phpwordpress

解决方案


是的,使用'nopaging' => true'ignore_sticky_posts'=>true

<?php $featured_posts = get_posts( [
    'posts_per_page' => 3,
    'orderby' => 'date', 
    'order' => 'DESC', 
    'update_post_term_cache' => false, 
    'update_post_meta_cache' => false,
    'nopaging' => true, 
    'ignore_sticky_posts'=>true,
    'meta_key'   => '_is_ns_featured_post',
    'meta_value' => 'yes',
    'fields'     => 'ids',
        ] );

    query_posts( array( 'post__not_in' => $featured_posts ) );

    while ( have_posts() ) : the_post();?>
        <div class="news-item-block col-md-4" role="article">
            <a class="news-item-image-link" href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail('news-grid-image'); ?>
            </a>
            <span class="news-item-date"><?php the_date( 'M d, Y' ); ?></span>
            <a class="news-item-title" href="<?php the_permalink(); ?>">
                <h1><?php the_title(); ?></h1>
            </a>
        </div>
    <?php endwhile;
    wp_reset_query();
?>

推荐阅读