Limit the number of words in the answers

4.88K viewsCore
1

Hi Rahul, amazing plugin 😉

I have a question about the limit of characters in the answers… Is it possible to limit the number of words in the answers?

I would like the answers have maximum 140 words, any idea?

Thanks for your time! Rgds!

1

I don’t know if there’s a function to do it. But you can do it including the maxlength attribute, o with jQuery.

But if you change the attribute, you are changing the php, so it will be override with the next update.

http://stackoverflow.com/questions/1363030/can-i-specify-maxlength-in-css
http://jsfiddle.net/TmsXG/13/

Thanks for your quick answer! 😉

But I need limit “words”… “maxlength” only works with characters… 🙁

Rgds!

Yeah, my bad. I’m pretty sure it can be done with javascript, but that is not my area, sorry…

Thanks! 😉

I have found this function:

function minWord($content){ global $post; $num = 100; //set this to the minimum number of words $content = $post->post_content; if (str_word_count($content) < $num) wp_die( __('Error: your post is below the minimum word count.') ); } add_action('publish_post', 'minWord');

Is it possible to change it to make it work the opposite?

Thanks!!!

function minWord($content) {
global $post;
$num = 140; //set this to the maximun number of words
$content = $post->post_content;
if (str_word_count($content) > $num) wp_die( __(‘your error message here.’) );
}

add_action(‘publish_post’, ‘minWord’);

This way show error with more of 140 words, but I don’t know where or how implement this function.

Thanks!

I will try! 😉