最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Display all posts ordered by word count

programmeradmin2浏览0评论

I have been using the following code on my other wordpress sites to show a list of all posts in the website oredered by word count. However, when I tried to use the same code in my new website wp 5.9 (I believe due to gutenberg) it shows the list and a number after the title, but the numbers are really small like 1 2 3, nowhere near the actual word count.

require_once('wp-blog-header.php'); 
$args = array('post_type' => 'post', 'posts_per_page' => 500, 'post_status' => 'publish'); 
$results = get_posts($args);
$nb_words = array();
$title = array();
foreach($results as $r){
  $nb_words[] = str_word_count( strip_tags( $r->post_content ));
  $title[] = $r->post_title;
}
array_multisort($nb_words, SORT_ASC, SORT_NUMERIC, $title);
echo "<ol>";
for ($i = 0; $i < sizeof($title); $i++) {
  echo '<li>'.$title[$i] . ' => ' . $nb_words[$i] . '<br></li>';
}
echo '</ol>';

Could you suggest why the str_word_count doesn't work here?

发布评论

评论列表(0)

  1. 暂无评论