I want to set the minimum word count as 100 for the blog post .
i have tried to use this codefunction minWord($content)
{
global $post;
$content = $post->post_content;
if (str_word_count($content) < 100 ) //set this to the minimum number of words
wp_die( __(‘Error: your post is below the minimum word count. It needs to be longer than 100 words.’) );
}
add_action(‘publish_post’, ‘minWord’);It shows the error message but then also it publishes the post instead it should not publish the post.
please help why its happening.Hello Rishabh,
You are validating post content on wrong action. Please download the latest plugin code for ‘bp-simple-front-end-post’ for the following url.
https://github.com/sbrajesh/bp-simple-front-end-postand try use the following code and let me know if it works or not
function buddydev_validate_post( $error, $post ) { if ( str_word_count( $post['bp_simple_post_text'] ) < 100 ) { $error['error'] = true; $error['message'] = __( "Please provide more than 100 words" ); } return $error; } add_filter( 'bsfep_validate_post', 'buddydev_validate_post', 10, 2 );
Thank You
Ravii have used the code provided by you in my theme’s function.php and it does not publish the post but also its not showing the error message instead it refreshes the screen why?
Hello Rishabh,
Have you download the updated code of “BP Simple Frontend Post” from the following url.
https://github.com/sbrajesh/bp-simple-front-end-postThank You
Raviyes sir thanks it worked, i understood your code also.But can you explain about this line
add_filter( ‘bsfep_validate_post’, ‘buddydev_validate_post’, 10, 2 );
as i need to change the minimum words to 200.
yes sir it worked.one more thing i need to ask after uploading the new posts the older posts are gone to previous page and instead it should go to the next page link.how to do that?
You must be logged in to reply to this topic.