WordPress:添加字数统计作为所有帖子的字段
在functions.php中,我创建了一个小函数来计算帖子中的单词数:
function prefix_wcount(){
global $post;
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(" ", $content));
$word_count = prefix_wcount();
}
现在我想向包含该数字的所有帖子添加一个字段。为此,我添加了
add_post_meta($post_id, $meta_key, $meta_value, $unique);
“This”,但并未添加此字段。我需要做什么才能实现这一点?
多谢
have in functions.php I have created a small function that counts words within a post:
function prefix_wcount(){
global $post;
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(" ", $content));
$word_count = prefix_wcount();
}
Now I would like to add a field to all posts that contains this number. For that I added
add_post_meta($post_id, $meta_key, $meta_value, $unique);
This does not add this field however. What do I need to do to make this happen?
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以先创建一个元框并简单地显示它。从技术上讲,您不需要可编辑字段。
这样您可能需要调整您的初始字数统计功能。
You could create a meta box first and simply display it. Technically you wouldn't need an editable field.
With this you may need to adjust your initial word count function.