在自定义WP_Query上设置字符限制

时间:2017-09-03 11:42:28

标签: php wordpress loops custom-fields

我已经在寻找解决方案2天了,但直到现在这些答案都没有帮助我。

我有一个自定义Wordpress循环的WP_Query,我想只在the_content中显示100个字符或更少(不是单词)的帖子。

<?php $movies = new WP_Query(
    array(
        'showposts' => 4,
    )
);
 if($movies->have_posts()) : while($movies->have_posts()) : $movies->the_post(); ?>

       <h2><?php the_title(); ?></h2>
       <div id="content"><?php the_content(); ?></div>

 <?php endwhile; endif; ?>

我是否可以使用任何核心解决方案作为阵列,或者我需要找到另一种方法来做到这一点?

我如何获得这些结果?

谢谢你们,你们太棒了。

1 个答案:

答案 0 :(得分:-1)

试试这个

<?php $movies = new WP_Query(
    array(
        'showposts' => 4,
    )
);
 if($movies->have_posts()) : while($movies->have_posts()) : $movies->the_post(); ?>

       <?php if(strlen(get_the_content()) <= 100): ?>

       <h2><?php the_title(); ?></h2>
       <div id="content"><?php the_content(); ?></div>
    <?php endif; ?>

 <?php endwhile; endif; ?>