【问题标题】:How to set number of posts on wordpress custom post如何在wordpress自定义帖子上设置帖子数量
【发布时间】:2020-01-06 19:12:17
【问题描述】:

我在functions.php 中创建了自定义帖子,一切正常,但我的循环仅显示9 个帖子。我能做些什么来展示所有这些? 我使用的循环:

<?php
            $custompost_loop = new WP_Query($custompost);
            if ($custompost_loop->have_posts()) : ?>
                <?php while ($custompost_loop->have_posts()) : $custompost_loop->the_post();
                    ?>
                    <div class="offer__single">
                        <h4 class="offer__title">
                            <?php echo get_the_title(); ?>
                        </h4>
                    </div>
                <?php
                endwhile;
                ?>
            <?php endif;
            wp_reset_postdata(); ?>

【问题讨论】:

    标签: php wordpress function loops


    【解决方案1】:
    $custompost = array(
        'posts_per_page'   => -1,
        'post_type'        => 'your_post_type',
    );
     $custompost_loop = new WP_Query( $custompost );
    

    在您的情况下,您可以将 'posts_per_page' =&gt; -1, 添加到您的 $custompost 数组中

    【讨论】:

    • 太好了,我忘记了 funcions.php 大声笑爱你,谢谢你的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 2016-04-27
    • 2016-12-29
    • 1970-01-01
    • 2016-11-29
    相关资源
    最近更新 更多