BuddyDev

Search

minimum word count

  • Participant
    Level: Initiated
    Posts: 18
    RISHABH GOEL on #10794

    I want to set the minimum word count as 100 for the blog post .
    i have tried to use this code

    function 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.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #10795

    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-post

    and 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
    Ravi

  • Participant
    Level: Initiated
    Posts: 18
    RISHABH GOEL on #10796

    i 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?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #10797

    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-post

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 18
    RISHABH GOEL on #10798

    yes 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.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #10799

    Hello Rishabh,

    It is just a filter provided by “BP Simple Frontend Post” to validated the form before saving the post.

    Just replace 100 with 200 in the condition and message string as well. It will work

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 18
    RISHABH GOEL on #10800

    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?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #10818

    Hello Rishabh,

    Sorry but didn’t get your question. Are you talking about pagination. Please make me more clear on this.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 18
    RISHABH GOEL on #10868

    yes,exactly i am talking about the pagination

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #10896

    Hello Rishabh,

    I have checked the BuddyBlog pagination as it seems working fine as expected behaviour i.e. New post comes first and so on.

    Thank You
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved